Skip to content

Commit

Permalink
build(core/rust): exclude ui module from TT build
Browse files Browse the repository at this point in the history
  • Loading branch information
mmilata committed Oct 5, 2021
1 parent 9d8ed08 commit 062e921
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ test: ## run unit tests
cd tests ; ./run_tests.sh $(TESTOPTS)

test_rust: ## run rs unit tests
cd embed/rust ; cargo test --features test -- --test-threads=1
cd embed/rust ; cargo test --features test,ui,ui_debug -- --test-threads=1

test_emu: ## run selected device tests from python-trezor
$(EMU_TEST) $(PYTEST) $(TESTPATH)/device_tests $(TESTOPTS)
Expand Down
7 changes: 7 additions & 0 deletions core/SConscript.firmware
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import os
BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0')
EVERYTHING = BITCOIN_ONLY != '1'
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
NEW_UI = TREZOR_MODEL == '1' or os.environ.get('NEW_UI', '0') == '1'

FEATURE_FLAGS = {
"RDI": True,
Expand Down Expand Up @@ -181,6 +182,10 @@ SOURCE_MOD += [
SOURCE_MOD += [
'embed/extmod/rustmods/modtrezorproto.c',
]
if NEW_UI:
SOURCE_MOD += [
'embed/extmod/rustmods/modtrezorui2.c',
]

# modutime
SOURCE_MOD += [
Expand Down Expand Up @@ -687,6 +692,8 @@ def cargo_build():
features = []
if BITCOIN_ONLY == "1":
features.append("bitcoin_only")
if NEW_UI:
features.append("ui")

return f'cd embed/rust; cargo build {profile} --target={RUST_TARGET} --target-dir=../../build/firmware/rust --features "{" ".join(features)}"'

Expand Down
7 changes: 7 additions & 0 deletions core/SConscript.unix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import os
BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0')
EVERYTHING = BITCOIN_ONLY != '1'
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
NEW_UI = TREZOR_MODEL == '1' or ARGUMENTS.get('NEW_UI', '0') == '1'

FEATURE_FLAGS = {
"SECP256K1_ZKP": False,
Expand Down Expand Up @@ -178,6 +179,10 @@ SOURCE_MOD += [
SOURCE_MOD += [
'embed/extmod/rustmods/modtrezorproto.c',
]
if NEW_UI:
SOURCE_MOD += [
'embed/extmod/rustmods/modtrezorui2.c',
]

# modutime
SOURCE_MOD += [
Expand Down Expand Up @@ -637,6 +642,8 @@ def cargo_build():
features = []
if BITCOIN_ONLY == "1":
features.append("bitcoin_only")
if NEW_UI:
features.append("ui")

return f'cd embed/rust; cargo build {profile} --target-dir=../../build/unix/rust --features "{" ".join(features)}"'

Expand Down
7 changes: 0 additions & 7 deletions core/embed/extmod/modtrezorui/modtrezorui.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,11 @@
#if MICROPY_PY_TREZORUI

#include "embed/extmod/trezorobj.h"
#include "librust.h"
#include "modtrezorui-display.h"

STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorui_layout_new_example_obj,
ui_layout_new_example);

STATIC const mp_rom_map_elem_t mp_module_trezorui_globals_table[] = {
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorui)},
{MP_ROM_QSTR(MP_QSTR_Display), MP_ROM_PTR(&mod_trezorui_Display_type)},

{MP_ROM_QSTR(MP_QSTR_layout_new_example),
MP_ROM_PTR(&mod_trezorui_layout_new_example_obj)},
};

STATIC MP_DEFINE_CONST_DICT(mp_module_trezorui_globals,
Expand Down
50 changes: 50 additions & 0 deletions core/embed/extmod/rustmods/modtrezorui2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This file is part of the Trezor project, https://trezor.io/
*
* Copyright (c) SatoshiLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "py/runtime.h"

#if MICROPY_PY_TREZORUI2

#include "librust.h"

/// def layout_new_example(text: str) -> None:
/// """Example layout."""
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorui2_layout_new_example_obj,
ui_layout_new_example);


STATIC const mp_rom_map_elem_t mp_module_trezorui2_globals_table[] = {
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorui2)},

{MP_ROM_QSTR(MP_QSTR_layout_new_example),
MP_ROM_PTR(&mod_trezorui2_layout_new_example_obj)},
};

STATIC MP_DEFINE_CONST_DICT(mp_module_trezorui2_globals,
mp_module_trezorui2_globals_table);

const mp_obj_module_t mp_module_trezorui2 = {
.base = {&mp_type_module},
.globals = (mp_obj_dict_t *)&mp_module_trezorui2_globals,
};

MP_REGISTER_MODULE(MP_QSTR_trezorui2, mp_module_trezorui2,
MICROPY_PY_TREZORUI2);

#endif // MICROPY_PY_TREZORUI2
1 change: 1 addition & 0 deletions core/embed/firmware/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
#define MICROPY_PY_TREZORUI (1)
#define MICROPY_PY_TREZORUTILS (1)
#define MICROPY_PY_TREZORPROTO (1)
#define MICROPY_PY_TREZORUI2 (1)

#ifdef SYSTEM_VIEW
#define MP_PLAT_PRINT_STRN(str, len) segger_print(str, len)
Expand Down
1 change: 1 addition & 0 deletions core/embed/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ build = "build.rs"

[features]
bitcoin_only = []
ui = []
ui_debug = []
test = ["cc", "glob"]

Expand Down
2 changes: 2 additions & 0 deletions core/embed/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ mod micropython;
mod protobuf;
mod trace;
mod trezorhal;

#[cfg(feature = "ui")]
#[macro_use]
mod ui;
mod util;
Expand Down
1 change: 1 addition & 0 deletions core/embed/unix/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ extern const struct _mp_print_t mp_stderr_print;
#define MICROPY_PY_TREZORUI (1)
#define MICROPY_PY_TREZORUTILS (1)
#define MICROPY_PY_TREZORPROTO (1)
#define MICROPY_PY_TREZORUI2 (1)

#define MP_STATE_PORT MP_STATE_VM

Expand Down

0 comments on commit 062e921

Please sign in to comment.