From f8f2cc36abe3e837512866543049f359cf76437b Mon Sep 17 00:00:00 2001 From: cepetr Date: Thu, 8 Aug 2024 17:18:32 +0200 Subject: [PATCH] refactor(core/build): remove hardcoded build path [no changelog] --- core/SConscript.bootloader | 3 ++- core/SConscript.bootloader_emu | 3 ++- core/SConscript.firmware | 3 ++- core/SConscript.unix | 3 ++- core/embed/rust/build.rs | 21 +++++++++------------ core/embed/rust/src/protobuf/defs.rs | 17 +---------------- 6 files changed, 18 insertions(+), 32 deletions(-) diff --git a/core/SConscript.bootloader b/core/SConscript.bootloader index e5226cd31..8a1a0ce0e 100644 --- a/core/SConscript.bootloader +++ b/core/SConscript.bootloader @@ -283,8 +283,9 @@ def cargo_build(): ] bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS) + build_dir = str(Dir('.').abspath) - return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts) + return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts) rust = env.Command( target=RUST_LIBPATH, diff --git a/core/SConscript.bootloader_emu b/core/SConscript.bootloader_emu index 9d0627cbc..c7483132a 100644 --- a/core/SConscript.bootloader_emu +++ b/core/SConscript.bootloader_emu @@ -300,8 +300,9 @@ def cargo_build(): ] bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS) + build_dir = str(Dir('.').abspath) - return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; cd embed/rust; cargo build --profile {RUST_PROFILE} ' + ' '.join(cargo_opts) + return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build --profile {RUST_PROFILE} ' + ' '.join(cargo_opts) rust = env.Command( target=RUST_LIBPATH, diff --git a/core/SConscript.firmware b/core/SConscript.firmware index ca818a3a5..8c1d19776 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -861,8 +861,9 @@ def cargo_build(): env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS) + build_dir = str(Dir('.').abspath) - return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts) + return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts) rust = env.Command( target=RUST_LIBPATH, diff --git a/core/SConscript.unix b/core/SConscript.unix index d51ab2836..6a65b17db 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -897,8 +897,9 @@ def cargo_build(): env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS) + build_dir = str(Dir('.').abspath) - return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; cd embed/rust; cargo build --profile {RUST_PROFILE} --target-dir=../../build/unix/rust --no-default-features --features "{" ".join(features)}" --target {TARGET}' + return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build --profile {RUST_PROFILE} --target-dir=../../build/unix/rust --no-default-features --features "{" ".join(features)}" --target {TARGET}' rust = env.Command( target=RUST_LIBPATH, diff --git a/core/embed/rust/build.rs b/core/embed/rust/build.rs index 543cf5046..e1cdaaefb 100644 --- a/core/embed/rust/build.rs +++ b/core/embed/rust/build.rs @@ -14,6 +14,10 @@ fn main() { link_core_objects(); } +fn build_dir() -> String { + env::var("BUILD_DIR").expect("BUILD_DIR not defined") +} + const DEFAULT_BINDGEN_MACROS_COMMON: &[&str] = &[ "-I../unix", "-I../trezorhal/unix", @@ -94,14 +98,7 @@ fn generate_qstr_bindings() { is_global: false, }) // Pass in correct include paths. - .clang_args(&[ - "-I", - if is_firmware() { - "../../build/firmware" - } else { - "../../build/unix" - }, - ]) + .clang_args(&["-I", &build_dir()]) // Customize the standard types. .use_core() .ctypes_prefix("cty") @@ -127,6 +124,8 @@ fn generate_qstr_bindings() { fn prepare_bindings() -> bindgen::Builder { let mut bindings = bindgen::Builder::default(); + let build_dir_include = format!("-I{}", build_dir()); + let mut clang_args: Vec<&str> = Vec::new(); let bindgen_macros_env = env::var("BINDGEN_MACROS").ok(); @@ -142,12 +141,12 @@ fn prepare_bindings() -> bindgen::Builder { bindings = bindings.clang_args(["-DNEW_RENDERING"]); } + clang_args.push(&build_dir_include); + // Pass in correct include paths and defines. if is_firmware() { clang_args.push("-nostdinc"); - clang_args.push("-I../../build/firmware"); - // Append gcc-arm-none-eabi's include paths. let cc_output = Command::new("arm-none-eabi-gcc") .arg("-E") @@ -168,8 +167,6 @@ fn prepare_bindings() -> bindgen::Builder { .map(|s| format!("-I{}", s.trim())); bindings = bindings.clang_args(include_args); - } else { - clang_args.push("-I../../build/unix"); } bindings = bindings.clang_args(&clang_args); diff --git a/core/embed/rust/src/protobuf/defs.rs b/core/embed/rust/src/protobuf/defs.rs index cdae0d22f..acf416568 100644 --- a/core/embed/rust/src/protobuf/defs.rs +++ b/core/embed/rust/src/protobuf/defs.rs @@ -109,24 +109,9 @@ struct NameDef { msg_offset: u16, } -#[cfg(target_arch = "arm")] macro_rules! proto_def_path { ($filename:expr) => { - concat!( - env!("CARGO_MANIFEST_DIR"), - "/../../build/firmware/rust/", - $filename - ) - }; -} -#[cfg(not(target_arch = "arm"))] -macro_rules! proto_def_path { - ($filename:expr) => { - concat!( - env!("CARGO_MANIFEST_DIR"), - "/../../build/unix/rust/", - $filename - ) + concat!(env!("BUILD_DIR"), "/rust/", $filename) }; }