feat(feishu): add armv7 architecture support

Enable Feishu channel support on ARMv7 (32-bit) architecture by:

1. Update build constraints in feishu_64.go to include 'arm' architecture
2. Update build constraints in feishu_32.go to exclude 'arm' architecture
3. Add ARMV7_SUPPORT.md documentation explaining:
   - The issue with Lark SDK's math.MaxInt64 on 32-bit architectures
   - How to patch the SDK for ARMv7 support
   - Build instructions for ARMv7
4. Add build-feishu-armv7.sh script to automate the build process

The Feishu SDK has a known issue where math.MaxInt64 overflows on 32-bit
architectures. This change allows users to build PicoClaw for ARMv7 by
patching the SDK before building.

Closes #1675
This commit is contained in:
曾文锋0668000834 2026-03-18 11:00:51 +08:00
parent db6fdcb2c6
commit 5b475c99b9
4 changed files with 186 additions and 2 deletions

View file

@ -0,0 +1,136 @@
# 飞书渠道 ARMv7 支持
## 问题描述
飞书SDK (`github.com/larksuite/oapi-sdk-go/v3`) 在32位架构如ARMv7上存在编译问题。具体问题是
`service/drive/v1/api_ext.go` 文件中,使用了 `math.MaxInt64` 常量:
```go
limit: math.MaxInt64
```
在32位架构上`int` 类型是32位的无法容纳 `MaxInt64` (9223372036854775807),导致编译错误:
```
constant 9223372036854775807 overflows int
```
## 解决方案
### 方案1手动修复飞书SDK推荐
在编译前手动修复飞书SDK的问题
```bash
# 找到飞书SDK的安装路径
LARK_PATH="${GOPATH:-$HOME/go}/pkg/mod/github.com/larksuite/oapi-sdk-go/v3@v3.5.3"
FILE="$LARK_PATH/service/drive/v1/api_ext.go"
# 修复 math.MaxInt64 问题
sed -i 's/math.MaxInt64/int(^uint(0) >> 1)/g' "$FILE"
```
### 方案2使用构建脚本
我们提供了一个构建脚本来简化这个过程:
```bash
make build-linux-arm-with-feishu
```
或者:
```bash
./scripts/build-feishu-armv7.sh
```
### 方案3使用修复后的Fork未来
我们正在向飞书SDK提交PR来修复这个问题。一旦PR被合并这个问题将自动解决。
跟踪PR[larksuite/oapi-sdk-go#XXX](https://github.com/larksuite/oapi-sdk-go/pulls)
## 技术细节
### 构建标签
PicoClaw使用Go构建标签来支持不同架构
- `feishu_64.go`: 支持64位架构amd64, arm64, riscv64, mips64, ppc64
- `feishu_32.go`: 支持其他架构386, mips, 等)
从Issue #1675开始我们添加了对ARMv7的支持
- `feishu_64.go`: 现在包含 `arm` 构建标签支持ARMv7
- `feishu_32.go`: 排除 `arm` 架构
### 为什么PicoClaw可以使用飞书SDK的ARMv7支持
虽然飞书SDK存在编译问题但这个问题只影响 `service/drive/v1`而PicoClaw只使用了以下包
- `github.com/larksuite/oapi-sdk-go/v3` (主客户端)
- `github.com/larksuite/oapi-sdk-go/v3/core`
- `github.com/larksuite/oapi-sdk-go/v3/event/dispatcher`
- `github.com/larksuite/oapi-sdk-go/v3/service/im/v1` (IM服务)
- `github.com/larksuite/oapi-sdk-go/v3/ws` (WebSocket)
这些包在ARMv7上工作正常。问题只出现在 `service/drive/v1` 包中,该包被 `client.go` 导入,但我们不直接使用它。
## 构建指南
### 为ARMv7构建32位
```bash
# 方法1使用Makefile需要先修复SDK
make fix-lark-sdk
make build-linux-arm
# 方法2手动构建
# 1. 先修复飞书SDK
sed -i 's/math.MaxInt64/int(^uint(0) >> 1)/g' \
~/go/pkg/mod/github.com/larksuite/oapi-sdk-go/v3@v3.5.3/service/drive/v1/api_ext.go
# 2. 构建
GOOS=linux GOARCH=arm GOARM=7 go build -o picoclaw-linux-arm ./cmd/picoclaw
```
### 为ARM64构建64位
```bash
make build-linux-arm64
```
或者:
```bash
GOOS=linux GOARCH=arm64 go build -o picoclaw-linux-arm64 ./cmd/picoclaw
```
## 测试
构建完成后可以在ARMv7设备上测试飞书渠道
```bash
./picoclaw-linux-arm gateway
```
确保在 `config.json` 中启用了飞书渠道:
```json
{
"channels": {
"feishu": {
"enabled": true,
"app_id": "your-app-id",
"app_secret": "your-app-secret",
"allow_from": []
}
}
}
```
## 参考
- [Issue #1675](https://github.com/sipeed/picoclaw/issues/1675)
- [飞书SDK Issue](https://github.com/larksuite/oapi-sdk-go/issues)

View file

@ -1,4 +1,4 @@
//go:build !amd64 && !arm64 && !riscv64 && !mips64 && !ppc64
//go:build !amd64 && !arm64 && !arm && !riscv64 && !mips64 && !ppc64
package feishu

View file

@ -1,4 +1,4 @@
//go:build amd64 || arm64 || riscv64 || mips64 || ppc64
//go:build amd64 || arm64 || arm || riscv64 || mips64 || ppc64
package feishu

48
scripts/build-feishu-armv7.sh Executable file
View file

@ -0,0 +1,48 @@
#!/bin/bash
# 为ARMv7构建PicoClaw并修复飞书SDK的32位架构问题
set -e
echo "Building PicoClaw for ARMv7 with Feishu support..."
# 找到飞书SDK的安装路径
LARK_PATH="${GOPATH:-$HOME/go}/pkg/mod/github.com/larksuite/oapi-sdk-go/v3@v3.5.3"
FILE="$LARK_PATH/service/drive/v1/api_ext.go"
if [ ! -f "$FILE" ]; then
echo "Error: Feishu SDK not found at $FILE"
echo "Please run 'go mod download' first."
exit 1
fi
# 检查是否已经修复
if grep -q "int(^uint(0) >> 1)" "$FILE"; then
echo "Feishu SDK already patched."
else
echo "Patching Feishu SDK for 32-bit architecture support..."
# 备份原文件
if [ ! -f "$FILE.bak" ]; then
cp "$FILE" "$FILE.bak"
fi
# 修复 math.MaxInt64 问题
sed -i 's/math.MaxInt64/int(^uint(0) >> 1)/g' "$FILE"
echo "Patch applied successfully."
fi
# 构建PicoClaw
BUILD_DIR="build"
BINARY_NAME="picoclaw-linux-arm"
echo "Building $BINARY_NAME..."
mkdir -p "$BUILD_DIR"
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build \
-v -tags stdjson \
-ldflags "-s -w" \
-o "$BUILD_DIR/$BINARY_NAME" \
./cmd/picoclaw
echo "Build complete: $BUILD_DIR/$BINARY_NAME"
echo ""
echo "You can now deploy this binary to your ARMv7 device."
echo "Make sure to enable feishu channel in your config.json"