Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:hammer: Improve Linux build scripts (#17632)

未来方舟40c148b56e4d
diff --git a/.gitignore b/.gitignore
index b4718a8ca2..53a3ea8d08 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,5 +37,8 @@ logs
package-lock.json
yarn.lock
+# musl toolchain
+muslbin/
+
# Workflows
**/__pycache__
diff --git a/scripts/linux-build.sh b/scripts/linux-build.sh
index 6f514a4ee2..4ea89bb9b4 100755
--- a/scripts/linux-build.sh
+++ b/scripts/linux-build.sh
@@ -66,18 +66,52 @@ export GOPROXY=https://mirrors.aliyun.com/goproxy/
export CGO_ENABLED=1
export GOOS=linux
+setup_cc() {
+ local arch=$1
+ local target_prefix
+ if [[ "$arch" == "amd64" ]]; then
+ target_prefix="x86_64-linux-musl"
+ elif [[ "$arch" == "arm64" ]]; then
+ target_prefix="aarch64-linux-musl"
+ fi
+
+ local original_cc=~/${target_prefix}-cross/bin/${target_prefix}-gcc
+
+ if [ -x "$original_cc" ]; then
+ export CC="$original_cc"
+ elif command -v ${target_prefix}-gcc >/dev/null 2>&1; then
+ export CC=$(command -v ${target_prefix}-gcc)
+ elif [[ "$arch" == "amd64" && "$(uname -m)" == "x86_64" ]] && command -v musl-gcc >/dev/null 2>&1; then
+ export CC=$(command -v musl-gcc)
+ elif [[ "$arch" == "arm64" && "$(uname -m)" == "aarch64" ]] && command -v musl-gcc >/dev/null 2>&1; then
+ export CC=$(command -v musl-gcc)
+ else
+ local muslbin_dir="$PROJECT_ROOT/muslbin"
+ local toolchain_dir="$muslbin_dir/${target_prefix}-cross"
+ local downloaded_cc="$toolchain_dir/bin/${target_prefix}-gcc"
+
+ if [ ! -x "$downloaded_cc" ]; then
+ echo "CC not found, downloading ${target_prefix}-cross..."
+ mkdir -p "$muslbin_dir"
+ curl -L "https://musl.cc/${target_prefix}-cross.tgz" | tar -xz -C "$muslbin_dir"
+ fi
+ export CC="$downloaded_cc"
+ fi
+ echo "Using CC=$CC"
+}
+
if [[ "$TARGET" == 'amd64' || "$TARGET" == 'all' ]]; then
echo
echo 'Building Kernel amd64'
export GOARCH=amd64
- export CC=~/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc
+ setup_cc amd64
go build -buildmode=pie -tags fts5 -v -o "../app/kernel-linux/SiYuan-Kernel" -ldflags "-s -w -extldflags -static-pie" .
fi
if [[ "$TARGET" == 'arm64' || "$TARGET" == 'all' ]]; then
echo
echo 'Building Kernel arm64'
export GOARCH=arm64
- export CC=~/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
+ setup_cc arm64
go build -buildmode=pie -tags fts5 -v -o "../app/kernel-linux-arm64/SiYuan-Kernel" -ldflags "-s -w -extldflags -static-pie" .
fi