cmake: Read RUSTFLAGS from environment and propagate correctly
What changed, and why it matters
This commit changes how build flags for the Rust parts of the BitBox02 firmware are handled. Previously, the project always overwrote RUSTFLAGS with its own internal settings, which meant any RUSTFLAGS set in the environment were silently ignored. The fix reads RUSTFLAGS from the environment first and then appends the project's required flags. This is a build-hygiene improvement; it does not directly fix a vulnerability, but it prevents a class of mistakes where important compiler warnings or hardening flags could be accidentally dropped during compilation.
No immediate user action required. Developers should verify that CI builds still fail on Rust warnings and that any externally supplied RUSTFLAGS are correctly reflected in build logs. Consider documenting supported environment variables for reproducible builds.
Security signals we found
Build flag propagation gap closed
Environment-supplied RUSTFLAGS no longer overwritten
CI warning-as-errors flag now reaches Rust compiler
Defensive build-hardening improvement
Evidence from the diff
The patch modifies CMakeLists.txt to capture $ENV{RUSTFLAGS} into a CMake variable before src/CMakeLists.txt appends project-specific flags. It also changes src/CMakeLists.txt to use string(APPEND RUSTFLAGS …) instead of set(RUSTFLAGS …), so environment-provided flags are preserved. The CI workflow moves RUSTFLAGS: “-Dwarnings” from per-job container env to the workflow-level env, ensuring it is propagated into the build environment where CMake can now read it. The change is defensive: it closes a gap where environment-supplied Rust compiler warnings/hardening options were silently discarded.
Changed components
BitBox02 firmware build system (CMake)Rust firmware components compiled via cargoGitHub Actions CI workflow ci-common.ymlInspect captured patch +10 / −8
diff --git a/.github/workflows/ci-common.yml b/.github/workflows/ci-common.yml
index 8aa3cd8..1487b93 100644
--- a/.github/workflows/ci-common.yml
+++ b/.github/workflows/ci-common.yml
@@ -10,6 +10,9 @@ on:
container-version:
required: true
type: string
+env:
+ RUSTFLAGS: "-Dwarnings"
+ CFLAGS: "-Werror"
jobs:
check-sigs:
@@ -54,8 +57,6 @@ jobs:
runs-on: ubuntu-22.04
container:
image: ${{ inputs.container-repo }}:${{ inputs.container-version }}
- env:
- RUSTFLAGS: "-Dwarnings"
steps:
- name: Clone the repo
uses: actions/checkout@v4
@@ -81,8 +82,6 @@ jobs:
runs-on: ubuntu-22.04
container:
image: ${{ inputs.container-repo }}:${{ inputs.container-version }}
- env:
- RUSTFLAGS: "-Dwarnings"
steps:
- name: Clone the repo
uses: actions/checkout@v4
@@ -170,8 +169,6 @@ jobs:
runs-on: ubuntu-22.04
container:
image: ${{ inputs.container-repo }}:${{ inputs.container-version }}
- env:
- RUSTFLAGS: "-Dwarnings"
steps:
- name: Clone the repo
uses: actions/checkout@v4
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2fe13fb..bc172c3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -243,6 +243,10 @@ set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_C_FLAGS_DEBUG "-Os -ggdb")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -ggdb -DNDEBUG")
+if(DEFINED ENV{RUSTFLAGS})
+ set(RUSTFLAGS $ENV{RUSTFLAGS})
+endif()
+
#-----------------------------------------------------------------------------
# Print system information and build options
@@ -270,6 +274,7 @@ message(STATUS "Compiler cache: ${CMAKE_C_COMPILER_LAUNCHER}")
message(STATUS "Linker: ${CMAKE_LINKER}")
message(STATUS "Archiver: ${CMAKE_AR}")
message(STATUS "Default CFLAGS: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}")
+message(STATUS "Default RUSTFLAGS: ${RUSTFLAGS}")
message(STATUS "Default EXE LDFLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
message(STATUS " - Options -")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c6344c5..d510e17 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -230,12 +230,12 @@ else()
set(RUST_PROFILE "release")
set(RUST_CARGO_FLAGS "--release")
# For binary reproducibility, strip path prefixes that can be different depending on environment (e.g. /home/<user>, etc.).
- set(RUSTFLAGS "--remap-path-prefix=${CMAKE_CURRENT_SOURCE_DIR}/rust=src --remap-path-prefix=$ENV{HOME}=")
+ string(APPEND RUSTFLAGS " --remap-path-prefix=${CMAKE_CURRENT_SOURCE_DIR}/rust=src --remap-path-prefix=$ENV{HOME}=")
endif()
# Use libsecp256k1 that we link ourselves.
# See https://github.com/rust-bitcoin/rust-secp256k1/tree/7c8270a8506e31731e540fab7ee1abde1f48314e/secp256k1-sys#linking-to-external-symbols
-set(RUSTFLAGS "${RUSTFLAGS} --cfg=rust_secp_no_symbol_renaming")
+string(APPEND RUSTFLAGS " --cfg=rust_secp_no_symbol_renaming")
if(CMAKE_CROSSCOMPILING)
set(RUST_TARGET_ARCH thumbv7em-none-eabi)
Why this scored 20/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.