An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Statically link Linux release kernels in Actions https://github.com/siyuan-note/siyuan/issues/20618
Daniel7995605fedd1
diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.ymlindex 6e7ecc3255..de311d5026 100644--- a/.github/workflows/desktop-build.yml+++ b/.github/workflows/desktop-build.yml@@ -41,6 +41,22 @@ jobs:cache: true- run: go version+ - name: Set up Linux musl compiler+ id: musl-compiler+ if: fromJSON(inputs.config).goos == 'linux'+ shell: bash+ env:+ GOARCH: ${{ fromJSON(inputs.config).goarch }}+ run: |+ case "$GOARCH" in+ amd64) target_prefix=x86_64-linux-musl ;;+ arm64) target_prefix=aarch64-linux-musl ;;+ *) echo "Unsupported Linux architecture: $GOARCH"; exit 1 ;;+ esac+ curl --fail --location --retry 3 "https://musl.cc/${target_prefix}-cross.tgz" -o "$RUNNER_TEMP/musl-cross.tgz"+ tar -xzf "$RUNNER_TEMP/musl-cross.tgz" -C "$RUNNER_TEMP"+ echo "cc=$RUNNER_TEMP/${target_prefix}-cross/bin/${target_prefix}-gcc" >> "$GITHUB_OUTPUT"+- name: Set up goversioninforun: go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo && go install github.com/josephspurrier/goversioninfo/cmd/goversioninfoif: "contains( fromJSON(inputs.config).goos, 'windows')"@@ -99,6 +115,7 @@ jobs:working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel- name: Building Kernel+ if: fromJSON(inputs.config).goos != 'linux'run: go build -tags "fts5 sqlcipher" -o "${{ fromJSON(inputs.config).kernel_path }}" -ldflags "${{ fromJSON(inputs.config).build_args_prefix }} github.com/${{ github.repository }}/kernel/util.${{ fromJSON(inputs.config).build_args_suffix }}"working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernelenv:@@ -107,6 +124,36 @@ jobs:GOOS: ${{ fromJSON(inputs.config).goos }}GOARCH: ${{ fromJSON(inputs.config).goarch }}+ - name: Building Linux Kernel+ if: fromJSON(inputs.config).goos == 'linux'+ run: go build -buildmode=pie -tags "fts5 sqlcipher" -o "${{ fromJSON(inputs.config).kernel_path }}" -ldflags "${{ fromJSON(inputs.config).build_args_prefix }} github.com/${{ github.repository }}/kernel/util.${{ fromJSON(inputs.config).build_args_suffix }} -extldflags -static-pie" .+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel+ env:+ GO111MODULE: on+ CGO_ENABLED: 1+ CC: ${{ steps.musl-compiler.outputs.cc }}+ GOOS: linux+ GOARCH: ${{ fromJSON(inputs.config).goarch }}++ - name: Verify static Linux Kernel+ if: fromJSON(inputs.config).goos == 'linux'+ shell: bash+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel+ env:+ KERNEL_PATH: ${{ fromJSON(inputs.config).kernel_path }}+ LC_ALL: C+ run: |+ program_headers="$(readelf -lW "$KERNEL_PATH")"+ dynamic_section="$(readelf -dW "$KERNEL_PATH")"+ # 静态内核不应包含动态加载器或共享库依赖。+ if [[ "$program_headers" == *INTERP* || "$dynamic_section" == *"(NEEDED)"* ]]; then+ echo "Linux kernel must be statically linked"+ echo "$program_headers"+ echo "$dynamic_section"+ exit 1+ fi+ "$KERNEL_PATH" --version+- name: Snapshot raw ARM editor runtimeid: editor-runtimeif: fromJSON(inputs.config).goos == 'darwin' && fromJSON(inputs.config).goarch == 'arm64'diff --git a/scripts/test_editor_e2e_workflow.py b/scripts/test_editor_e2e_workflow.pyindex ed59a9cd87..ea8d693615 100644--- a/scripts/test_editor_e2e_workflow.py+++ b/scripts/test_editor_e2e_workflow.py@@ -6,6 +6,7 @@ from pathlib import Pathimport reimport shutilimport subprocess+import sysimport tarfileimport tempfileimport unittest@@ -27,6 +28,46 @@ def snapshot_command():class EditorWorkflowTests(unittest.TestCase):+ @unittest.skipUnless(sys.platform == "linux" and all(shutil.which(tool) for tool in ["bash", "gcc", "readelf"]),+ "Linux ELF verification requires native compiler and binutils")+ def test_linux_kernel_verification_rejects_dynamic_and_unusable_binaries(self):+ step = DESKTOP.split(" - name: Verify static Linux Kernel\n", 1)[1].split(" - ", 1)[0]+ command = step.split(" run: |\n", 1)[1]+ command = "\n".join(line[10:] for line in command.splitlines())+ with tempfile.TemporaryDirectory() as temporary:+ root = Path(temporary)+ source = root / "fixture.c"+ source.write_text(+ '#include <stdio.h>\n#include <string.h>\n'+ '#ifndef EXIT_CODE\n#define EXIT_CODE 0\n#endif\n'+ 'int main(int argc, char **argv) {\n'+ ' if (argc != 2 || strcmp(argv[1], "--version")) return 3;\n'+ ' puts("Linux kernel fixture");\n'+ ' return EXIT_CODE;\n}\n', encoding="utf-8")+ for name, flags, expected in [+ ("static-pie", ["-static-pie"], 0),+ ("dynamic", [], 1),+ ("shared", ["-shared", "-fPIC"], 1),+ ("broken-startup", ["-static-pie", "-DEXIT_CODE=7"], 7),+ ]:+ with self.subTest(name=name):+ binary = root / name+ subprocess.run(["gcc", *flags, str(source), "-o", str(binary)], check=True, capture_output=True)+ result = subprocess.run(["bash", "-euo", "pipefail", "-c", command],+ env={**os.environ, "KERNEL_PATH": str(binary), "LC_ALL": "C"},+ capture_output=True, text=True)+ self.assertEqual(result.returncode, expected, result.stdout + result.stderr)+ if expected == 1:+ self.assertIn("Linux kernel must be statically linked", result.stdout)+ else:+ self.assertIn("Linux kernel fixture", result.stdout)+ invalid = root / "invalid"+ invalid.write_text("not an ELF binary", encoding="utf-8")+ result = subprocess.run(["bash", "-euo", "pipefail", "-c", command],+ env={**os.environ, "KERNEL_PATH": str(invalid), "LC_ALL": "C"},+ capture_output=True, text=True)+ self.assertNotEqual(result.returncode, 0)+def test_windows_kernel_tests_cover_all_packages_with_cgo(self):kernel = job("kernel-tests-windows")compiler = kernel.split("- name: Set up Windows kernel test compiler\n", 1)[1].split(" - ", 1)[0]