From 35eec1d0005af9c7857b24140fe91262fe6e8059 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Fri, 14 Aug 2026 19:40:11 +0000 Subject: [PATCH] Force PIC as the final x64 compiler flag. --- .gitea/scripts/x86_64-linux-gnu-g++-pic | 2 ++ .gitea/scripts/x86_64-linux-gnu-gcc-pic | 2 ++ .gitea/workflows/release.yml | 6 ++++-- crates/bds-ui/tests/packaging_assets.rs | 23 +++++++++++++++++++++-- 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100755 .gitea/scripts/x86_64-linux-gnu-g++-pic create mode 100755 .gitea/scripts/x86_64-linux-gnu-gcc-pic diff --git a/.gitea/scripts/x86_64-linux-gnu-g++-pic b/.gitea/scripts/x86_64-linux-gnu-g++-pic new file mode 100755 index 0000000..8faac5b --- /dev/null +++ b/.gitea/scripts/x86_64-linux-gnu-g++-pic @@ -0,0 +1,2 @@ +#!/bin/sh +exec x86_64-linux-gnu-g++ "$@" -fPIC diff --git a/.gitea/scripts/x86_64-linux-gnu-gcc-pic b/.gitea/scripts/x86_64-linux-gnu-gcc-pic new file mode 100755 index 0000000..a884f88 --- /dev/null +++ b/.gitea/scripts/x86_64-linux-gnu-gcc-pic @@ -0,0 +1,2 @@ +#!/bin/sh +exec x86_64-linux-gnu-gcc "$@" -fPIC diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 4eda137..f196334 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -136,8 +136,6 @@ jobs: runs-on: linux-arm64 env: AR_x86_64_unknown_linux_gnu: x86_64-linux-gnu-ar - CC_x86_64_unknown_linux_gnu: x86_64-linux-gnu-gcc -fPIC - CXX_x86_64_unknown_linux_gnu: x86_64-linux-gnu-g++ -fPIC CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: x86_64-linux-gnu-gcc CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS: -C link-arg=--sysroot=/opt/ruds-x64-sysroot -C link-arg=-Wl,-rpath,$ORIGIN -L native=/opt/ruds-x64-sysroot/usr/lib/x86_64-linux-gnu -L native=/opt/ruds-x64-sysroot/lib/x86_64-linux-gnu PKG_CONFIG_ALLOW_CROSS: "1" @@ -168,6 +166,10 @@ jobs: run: | set -eu target=x86_64-unknown-linux-gnu + export CC="$PWD/.gitea/scripts/x86_64-linux-gnu-gcc-pic" + export CC_x86_64_unknown_linux_gnu="$PWD/.gitea/scripts/x86_64-linux-gnu-gcc-pic" + export CXX="$PWD/.gitea/scripts/x86_64-linux-gnu-g++-pic" + export CXX_x86_64_unknown_linux_gnu="$PWD/.gitea/scripts/x86_64-linux-gnu-g++-pic" unset ZSTD_SYS_USE_PKG_CONFIG cargo +${RUST_TOOLCHAIN} build --release --locked --target "$target" \ --package bds-ui --package bds-cli --package bds-mcp diff --git a/crates/bds-ui/tests/packaging_assets.rs b/crates/bds-ui/tests/packaging_assets.rs index ced2735..7cb1f1d 100644 --- a/crates/bds-ui/tests/packaging_assets.rs +++ b/crates/bds-ui/tests/packaging_assets.rs @@ -148,8 +148,8 @@ fn tagged_releases_are_built_and_packaged_with_rust_tools() { "publish", "PKG_CONFIG_ALLOW_CROSS", "CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER", - "CC_x86_64_unknown_linux_gnu: x86_64-linux-gnu-gcc -fPIC", - "CXX_x86_64_unknown_linux_gnu: x86_64-linux-gnu-g++ -fPIC", + "export CC_x86_64_unknown_linux_gnu=\"$PWD/.gitea/scripts/x86_64-linux-gnu-gcc-pic\"", + "export CXX_x86_64_unknown_linux_gnu=\"$PWD/.gitea/scripts/x86_64-linux-gnu-g++-pic\"", "unset ZSTD_SYS_USE_PKG_CONFIG", ] { assert!( @@ -260,3 +260,22 @@ fn tagged_releases_are_built_and_packaged_with_rust_tools() { assert!(release_source.contains("rewrite_macho_rpaths")); assert!(!release_source.contains("Linux releases contain the portable CLI tools")); } + +#[test] +fn x64_cross_compiler_wrappers_append_pic_last() { + for (script, compiler) in [ + ("x86_64-linux-gnu-gcc-pic", "x86_64-linux-gnu-gcc"), + ("x86_64-linux-gnu-g++-pic", "x86_64-linux-gnu-g++"), + ] { + let contents = fs::read_to_string( + Path::new(CRATE_DIR) + .join("../../.gitea/scripts") + .join(script), + ) + .unwrap(); + assert_eq!( + contents, + format!("#!/bin/sh\nexec {compiler} \"$@\" -fPIC\n") + ); + } +}