1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-15 20:19:23 +00:00

fix(core/rust): fix bindgen macros generation

[no changelog]
This commit is contained in:
tychovrahe 2024-04-25 16:44:42 +02:00
parent d349c44a58
commit cc192cd96f
5 changed files with 22 additions and 13 deletions

View File

@ -230,8 +230,6 @@ def cargo_build():
features.append("bootloader")
features.extend(FEATURES_AVAILABLE)
env.get("ENV")["BINDGEN_MACROS"] = tools.get_bindgen_defines(env.get("ALLDEFS"), ALLPATHS)
cargo_opts = [
f'--target={env.get("ENV")["RUST_TARGET"]}',
f'--target-dir=../../build/bootloader/rust',
@ -241,7 +239,9 @@ def cargo_build():
'-Z build-std-features=panic_immediate_abort',
]
return f'cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts)
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts)
rust = env.Command(
target=RUST_LIBPATH,

View File

@ -209,7 +209,7 @@ ALLPATHS = ['embed/rust',
'embed/unix',
'embed/extmod/modtrezorui',
'vendor/nanopb',
] + CPPPATH_MOD,
] + CPPPATH_MOD
env.Replace(
COPT=env.get('ENV').get('OPTIMIZE', '-Os'),
@ -291,7 +291,6 @@ def cargo_build():
features.append("ui")
features.append("bootloader")
env.get("ENV")["BINDGEN_MACROS"] = tools.get_bindgen_defines(env.get("ALLDEFS"), ALLPATHS)
cargo_opts = [
f'--target={RUST_TARGET}',
@ -302,7 +301,9 @@ def cargo_build():
'-Z build-std-features=panic_immediate_abort',
]
return f'cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts)
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts)
rust = env.Command(
target=RUST_LIBPATH,

View File

@ -780,8 +780,6 @@ def cargo_build():
features.extend(FEATURES_AVAILABLE)
env.get("ENV")["BINDGEN_MACROS"] = tools.get_bindgen_defines(env.get("ALLDEFS"), ALLPATHS)
cargo_opts = [
f'--target={env.get("ENV")["RUST_TARGET"]}',
f'--target-dir=../../build/firmware/rust',
@ -793,7 +791,9 @@ def cargo_build():
env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL
return f'cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts)
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts)
rust = env.Command(
target=RUST_LIBPATH,

View File

@ -871,9 +871,9 @@ def cargo_build():
if TREZOR_MODEL in ('R', '1'):
features.append('button')
env.get("ENV")["BINDGEN_MACROS"] = tools.get_bindgen_defines(env.get("ALLDEFS"), ALLPATHS)
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
return f'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}\'; 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,

View File

@ -153,9 +153,17 @@ def get_bindgen_defines(
) -> tuple(str, str):
rest_defs = []
for d in defines:
rest_defs.append(
f"-D{d}".replace('"<', "<").replace('>"', ">").replace('\\"', '"')
if type(d) is tuple:
d = f"-D{d[0]}={d[1]}"
else:
d = f"-D{d}"
d = (
d.replace('\\"', '"')
.replace("'", "'\"'\"'")
.replace('"<', "<")
.replace('>"', ">")
)
rest_defs.append(d)
for d in paths:
rest_defs.append(f"-I../../{d}")