mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 23:08:14 +00:00
refactor(core/build): remove hardcoded build path
[no changelog]
This commit is contained in:
parent
4312c08612
commit
a3fcc62655
@ -143,6 +143,7 @@ test: ## run unit tests
|
|||||||
cd tests ; ./run_tests.sh $(TESTOPTS)
|
cd tests ; ./run_tests.sh $(TESTOPTS)
|
||||||
|
|
||||||
test_rust: ## run rs unit tests
|
test_rust: ## run rs unit tests
|
||||||
|
export BUILD_DIR=$(abspath $(UNIX_BUILD_DIR)) ; \
|
||||||
cd embed/rust ; cargo test $(TESTOPTS) --target=$(RUST_TARGET) \
|
cd embed/rust ; cargo test $(TESTOPTS) --target=$(RUST_TARGET) \
|
||||||
--no-default-features --features $(MODEL_FEATURE),test \
|
--no-default-features --features $(MODEL_FEATURE),test \
|
||||||
-- --test-threads=1 --nocapture
|
-- --test-threads=1 --nocapture
|
||||||
@ -212,6 +213,7 @@ pyright:
|
|||||||
python ../tools/pyright_tool.py
|
python ../tools/pyright_tool.py
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
|
export BUILD_DIR=$(abspath $(UNIX_BUILD_DIR)) ; \
|
||||||
cd embed/rust ; cargo clippy $(TESTOPTS) --all-features --target=$(RUST_TARGET)
|
cd embed/rust ; cargo clippy $(TESTOPTS) --all-features --target=$(RUST_TARGET)
|
||||||
|
|
||||||
## code generation:
|
## code generation:
|
||||||
|
@ -283,8 +283,9 @@ def cargo_build():
|
|||||||
]
|
]
|
||||||
|
|
||||||
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
|
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(
|
rust = env.Command(
|
||||||
target=RUST_LIBPATH,
|
target=RUST_LIBPATH,
|
||||||
|
@ -300,8 +300,9 @@ def cargo_build():
|
|||||||
]
|
]
|
||||||
|
|
||||||
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
|
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(
|
rust = env.Command(
|
||||||
target=RUST_LIBPATH,
|
target=RUST_LIBPATH,
|
||||||
|
@ -861,8 +861,9 @@ def cargo_build():
|
|||||||
env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL
|
env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL
|
||||||
|
|
||||||
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
|
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(
|
rust = env.Command(
|
||||||
target=RUST_LIBPATH,
|
target=RUST_LIBPATH,
|
||||||
|
@ -897,8 +897,9 @@ def cargo_build():
|
|||||||
env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL
|
env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL
|
||||||
|
|
||||||
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
|
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(
|
rust = env.Command(
|
||||||
target=RUST_LIBPATH,
|
target=RUST_LIBPATH,
|
||||||
|
@ -14,6 +14,10 @@ fn main() {
|
|||||||
link_core_objects();
|
link_core_objects();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build_dir() -> String {
|
||||||
|
env::var("BUILD_DIR").expect("BUILD_DIR not defined")
|
||||||
|
}
|
||||||
|
|
||||||
const DEFAULT_BINDGEN_MACROS_COMMON: &[&str] = &[
|
const DEFAULT_BINDGEN_MACROS_COMMON: &[&str] = &[
|
||||||
"-I../unix",
|
"-I../unix",
|
||||||
"-I../trezorhal/unix",
|
"-I../trezorhal/unix",
|
||||||
@ -94,14 +98,7 @@ fn generate_qstr_bindings() {
|
|||||||
is_global: false,
|
is_global: false,
|
||||||
})
|
})
|
||||||
// Pass in correct include paths.
|
// Pass in correct include paths.
|
||||||
.clang_args(&[
|
.clang_args(&["-I", &build_dir()])
|
||||||
"-I",
|
|
||||||
if is_firmware() {
|
|
||||||
"../../build/firmware"
|
|
||||||
} else {
|
|
||||||
"../../build/unix"
|
|
||||||
},
|
|
||||||
])
|
|
||||||
// Customize the standard types.
|
// Customize the standard types.
|
||||||
.use_core()
|
.use_core()
|
||||||
.ctypes_prefix("cty")
|
.ctypes_prefix("cty")
|
||||||
@ -127,6 +124,8 @@ fn generate_qstr_bindings() {
|
|||||||
fn prepare_bindings() -> bindgen::Builder {
|
fn prepare_bindings() -> bindgen::Builder {
|
||||||
let mut bindings = bindgen::Builder::default();
|
let mut bindings = bindgen::Builder::default();
|
||||||
|
|
||||||
|
let build_dir_include = format!("-I{}", build_dir());
|
||||||
|
|
||||||
let mut clang_args: Vec<&str> = Vec::new();
|
let mut clang_args: Vec<&str> = Vec::new();
|
||||||
|
|
||||||
let bindgen_macros_env = env::var("BINDGEN_MACROS").ok();
|
let bindgen_macros_env = env::var("BINDGEN_MACROS").ok();
|
||||||
@ -142,12 +141,12 @@ fn prepare_bindings() -> bindgen::Builder {
|
|||||||
bindings = bindings.clang_args(["-DNEW_RENDERING"]);
|
bindings = bindings.clang_args(["-DNEW_RENDERING"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clang_args.push(&build_dir_include);
|
||||||
|
|
||||||
// Pass in correct include paths and defines.
|
// Pass in correct include paths and defines.
|
||||||
if is_firmware() {
|
if is_firmware() {
|
||||||
clang_args.push("-nostdinc");
|
clang_args.push("-nostdinc");
|
||||||
|
|
||||||
clang_args.push("-I../../build/firmware");
|
|
||||||
|
|
||||||
// Append gcc-arm-none-eabi's include paths.
|
// Append gcc-arm-none-eabi's include paths.
|
||||||
let cc_output = Command::new("arm-none-eabi-gcc")
|
let cc_output = Command::new("arm-none-eabi-gcc")
|
||||||
.arg("-E")
|
.arg("-E")
|
||||||
@ -168,8 +167,6 @@ fn prepare_bindings() -> bindgen::Builder {
|
|||||||
.map(|s| format!("-I{}", s.trim()));
|
.map(|s| format!("-I{}", s.trim()));
|
||||||
|
|
||||||
bindings = bindings.clang_args(include_args);
|
bindings = bindings.clang_args(include_args);
|
||||||
} else {
|
|
||||||
clang_args.push("-I../../build/unix");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bindings = bindings.clang_args(&clang_args);
|
bindings = bindings.clang_args(&clang_args);
|
||||||
|
@ -109,24 +109,9 @@ struct NameDef {
|
|||||||
msg_offset: u16,
|
msg_offset: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "arm")]
|
|
||||||
macro_rules! proto_def_path {
|
macro_rules! proto_def_path {
|
||||||
($filename:expr) => {
|
($filename:expr) => {
|
||||||
concat!(
|
concat!(env!("BUILD_DIR"), "/rust/", $filename)
|
||||||
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
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user