Skip to content

Commit 26c1902

Browse files
committed
Merge branch 'maint/cargo-cc-werror'
2 parents b94372e + 62667d7 commit 26c1902

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

.github/workflows/ci-common.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
container-version:
1111
required: true
1212
type: string
13+
env:
14+
RUSTFLAGS: "-Dwarnings"
15+
CFLAGS: "-Werror"
1316

1417
jobs:
1518
check-sigs:
@@ -54,8 +57,6 @@ jobs:
5457
runs-on: ubuntu-22.04
5558
container:
5659
image: ${{ inputs.container-repo }}:${{ inputs.container-version }}
57-
env:
58-
RUSTFLAGS: "-Dwarnings"
5960
steps:
6061
- name: Clone the repo
6162
uses: actions/checkout@v4
@@ -81,8 +82,6 @@ jobs:
8182
runs-on: ubuntu-22.04
8283
container:
8384
image: ${{ inputs.container-repo }}:${{ inputs.container-version }}
84-
env:
85-
RUSTFLAGS: "-Dwarnings"
8685
steps:
8786
- name: Clone the repo
8887
uses: actions/checkout@v4
@@ -170,8 +169,6 @@ jobs:
170169
runs-on: ubuntu-22.04
171170
container:
172171
image: ${{ inputs.container-repo }}:${{ inputs.container-version }}
173-
env:
174-
RUSTFLAGS: "-Dwarnings"
175172
steps:
176173
- name: Clone the repo
177174
uses: actions/checkout@v4

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG")
243243
set(CMAKE_C_FLAGS_DEBUG "-Os -ggdb")
244244
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -ggdb -DNDEBUG")
245245

246+
if(DEFINED ENV{RUSTFLAGS})
247+
set(RUSTFLAGS $ENV{RUSTFLAGS})
248+
endif()
249+
246250
#-----------------------------------------------------------------------------
247251
# Print system information and build options
248252

@@ -270,6 +274,7 @@ message(STATUS "Compiler cache: ${CMAKE_C_COMPILER_LAUNCHER}")
270274
message(STATUS "Linker: ${CMAKE_LINKER}")
271275
message(STATUS "Archiver: ${CMAKE_AR}")
272276
message(STATUS "Default CFLAGS: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}")
277+
message(STATUS "Default RUSTFLAGS: ${RUSTFLAGS}")
273278
message(STATUS "Default EXE LDFLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
274279
message(STATUS " - Options -")
275280
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ else()
230230
set(RUST_PROFILE "release")
231231
set(RUST_CARGO_FLAGS "--release")
232232
# For binary reproducibility, strip path prefixes that can be different depending on environment (e.g. /home/<user>, etc.).
233-
set(RUSTFLAGS "--remap-path-prefix=${CMAKE_CURRENT_SOURCE_DIR}/rust=src --remap-path-prefix=$ENV{HOME}=")
233+
string(APPEND RUSTFLAGS " --remap-path-prefix=${CMAKE_CURRENT_SOURCE_DIR}/rust=src --remap-path-prefix=$ENV{HOME}=")
234234
endif()
235235

236236
# Use libsecp256k1 that we link ourselves.
237237
# See https://github.com/rust-bitcoin/rust-secp256k1/tree/7c8270a8506e31731e540fab7ee1abde1f48314e/secp256k1-sys#linking-to-external-symbols
238-
set(RUSTFLAGS "${RUSTFLAGS} --cfg=rust_secp_no_symbol_renaming")
238+
string(APPEND RUSTFLAGS " --cfg=rust_secp_no_symbol_renaming")
239239

240240
if(CMAKE_CROSSCOMPILING)
241241
set(RUST_TARGET_ARCH thumbv7em-none-eabi)

src/rust/bitbox02-sys/build.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ pub fn main() -> Result<(), &'static str> {
270270
let arm_sysroot = env::var("CMAKE_SYSROOT").unwrap_or("/usr/local/arm-none-eabi".to_string());
271271
let arm_sysroot = format!("--sysroot={arm_sysroot}");
272272

273-
let extra_flags = if cross_compiling {
273+
let mut extra_flags = if cross_compiling {
274274
vec![
275275
"-D__SAMD51J20A__",
276276
"--target=thumbv7em-none-eabi",
@@ -284,6 +284,15 @@ pub fn main() -> Result<(), &'static str> {
284284
vec!["-DTESTING", "-D_UNIT_TEST_", "-DPRODUCT_BITBOX_MULTI=1"]
285285
};
286286

287+
// If user enables -Dwarnings for rust we also want to enable -Werror for C.
288+
if let Ok(rustflags) = std::env::var("CARGO_ENCODED_RUSTFLAGS") {
289+
for flag in rustflags.split('\x1f') {
290+
if flag == "-Dwarnings" {
291+
extra_flags.push("-Werror");
292+
}
293+
}
294+
}
295+
287296
let mut includes = vec![
288297
// $INCLUDES
289298
"../..",

test/hardware-fakes/include/fake_memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void memory_read_chunk_fake(uint32_t chunk_num, uint8_t* chunk_out);
2828
// Size: `FLASH_SHARED_DATA_LEN`.
2929
void memory_read_shared_bootdata_fake(uint8_t* chunk_out);
3030
void fake_memory_set_salt_root(const uint8_t* salt_root);
31+
const uint8_t* fake_memory_get_salt_root(void);
3132
void memory_bootloader_hash_fake(uint8_t* hash_out);
3233
void memory_set_bootloader_hash_fake(const uint8_t* fake_hash);
3334
#endif

test/hardware-fakes/src/fake_memory.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,14 @@ static uint8_t _salt_root[32] = {
225225
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
226226
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
227227
};
228+
228229
void fake_memory_set_salt_root(const uint8_t* salt_root)
229230
{
230231
memcpy(_salt_root, salt_root, 32);
231232
}
232-
bool __wrap_memory_get_salt_root(uint8_t* salt_root_out)
233+
const uint8_t* fake_memory_get_salt_root(void)
233234
{
234-
memcpy(salt_root_out, _salt_root, 32);
235-
return true;
235+
return _salt_root;
236236
}
237237

238238
// Arbitrary value.

test/unit-test/framework/src/mock_memory.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <stddef.h>
1919
#include <cmocka.h>
2020

21+
#include <fake_memory.h>
2122
#include <flags.h>
2223
#include <memory/memory.h>
2324
#include <stdio.h>
@@ -67,3 +68,9 @@ bool __wrap_memory_set_mnemonic_passphrase_enabled(bool enabled)
6768
check_expected(enabled);
6869
return mock();
6970
}
71+
72+
bool __wrap_memory_get_salt_root(uint8_t* salt_root_out)
73+
{
74+
memcpy(salt_root_out, fake_memory_get_salt_root(), 32);
75+
return true;
76+
}

0 commit comments

Comments
 (0)