Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Refactor rust build #1513

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d4452ee
chore: organize rust_c features
soralit Dec 24, 2024
f80cae4
chore: refactor cbindgen
soralit Dec 25, 2024
36e6930
chore: refactor chain interfaces
soralit Dec 25, 2024
22a3436
chore: refactor common interfaces
soralit Dec 25, 2024
869eb85
chore: refactor cbindgen
soralit Dec 25, 2024
d0dfcfc
split chain
ww3512687 Dec 25, 2024
d215260
split chain
ww3512687 Dec 25, 2024
4b27b6d
refactor: use features for code
soralit Dec 25, 2024
0ecfcf0
fix: all build
soralit Dec 25, 2024
a16a588
style: run rust fix
soralit Dec 25, 2024
f61832f
style: run rust fmt
soralit Dec 25, 2024
77362c6
style: run cargo fix
soralit Dec 25, 2024
81eb092
style: apply clippy suggestions
soralit Dec 26, 2024
e040887
style: run cargo fix
soralit Dec 26, 2024
d9b3125
style: fix warnings
soralit Dec 26, 2024
b10d0ec
1. split home widgets
ww3512687 Dec 26, 2024
878a1ad
chore: add defines
soralit Dec 26, 2024
0974721
chore: organize rust_c features
soralit Dec 24, 2024
a838895
chore: refactor cbindgen
soralit Dec 25, 2024
5f7ed31
chore: refactor chain interfaces
soralit Dec 25, 2024
6716a5b
chore: refactor common interfaces
soralit Dec 25, 2024
6b5c429
chore: refactor cbindgen
soralit Dec 25, 2024
f8743b6
refactor: use features for code
soralit Dec 25, 2024
dcbd809
fix: all build
soralit Dec 25, 2024
ce3f120
style: run rust fix
soralit Dec 25, 2024
5ba462a
style: run rust fmt
soralit Dec 25, 2024
81f717c
style: run cargo fix
soralit Dec 25, 2024
1658dd1
style: apply clippy suggestions
soralit Dec 26, 2024
cd96baf
style: run cargo fix
soralit Dec 26, 2024
7de3ede
style: fix warnings
soralit Dec 26, 2024
f456288
chore: add defines
soralit Dec 26, 2024
4ae02a3
Merge remote-tracking branch 'origin/refactor-rust-build' into refact…
ww3512687 Dec 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
77 changes: 47 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ foreach(_variableName ${_variableNames})
endif()
endforeach()

if(BTC_ONLY)
add_compile_definitions(BTC_ONLY)
add_compile_definitions(EXCLUDE_RUSTC)
endif()

set(COMMON_DEFINITIONS
USE_STDPERIPH_DRIVER
Expand All @@ -61,29 +57,46 @@ set(CRYPTO_INCLUDE_PATH
src/crypto/slip39/trezor-crypto
)

set(WIDGET_PATH "multi")
if(CYBERPUNK)
set(WIDGET_SUBPATH "multi/cyberpunk")
add_compile_definitions(CYBERPUNK_VERSION)
elseif(BTC_ONLY)
set(WIDGET_SUBPATH "btc_only/multi_sig")
set(WIDGET_PATH "btc_only")
add_compile_definitions(BTC_ONLY)
add_compile_definitions(EXCLUDE_RUSTC)
else()
add_compile_definitions(GENERAL_VERSION)
set(WIDGET_SUBPATH "multi/general")
endif()

set(GUI_CUSTOM_INCLUDE_PATH
src/ui/gui_widgets/${WIDGET_SUBPATH}
src/ui/gui_widgets/${WIDGET_PATH}
src/ui/gui_chain/${WIDGET_SUBPATH}
src/ui/gui_chain/${WIDGET_PATH}
src/ui/gui_wallet/${WIDGET_SUBPATH}
src/ui/gui_wallet/${WIDGET_PATH}
)

set(GUI_INCLUDE_PATH
src/ui
src/ui/gui_views
src/ui/gui_assets
src/ui/gui_assets/abi
src/ui/gui_frame
${GUI_CUSTOM_INCLUDE_PATH}
src/ui/gui_widgets
src/ui/gui_widgets/setting
src/ui/lv_i18n
src/ui/gui_model
src/ui/gui_analyze
src/ui/gui_chain
src/ui/gui_chain/btc
src/ui/gui_components
src/ui/wallet
src/ui/gui_wallet
)

if(BTC_ONLY)
list(APPEND GUI_INCLUDE_PATH src/ui/gui_widgets/btc_only src/ui/gui_widgets/btc_only/multi_sig src/ui/gui_widgets/general)
else()
list(APPEND GUI_INCLUDE_PATH src/ui/gui_chain/others src/ui/gui_widgets/general)
endif()

set(EXTERNAL_INCLUDE_PATH
external
external/ctaes
Expand Down Expand Up @@ -159,21 +172,37 @@ if(NOT BUILD_PRODUCTION)
list(APPEND INCLUDE_DIR test)
set(TEST_CMD test)
endif()

file(GLOB GUI_CUSTOM_VIEW_WIDGETS
src/ui/gui_views/*.c
src/ui/gui_views/general/*.c
src/ui/gui_widgets/*.c
src/ui/gui_widgets/general/*.c
src/ui/gui_wallet/*.c
src/ui/gui_chain/*.c
src/ui/gui_analyze/*.c
src/ui/gui_widgets/${WIDGET_SUBPATH}/*.c
src/ui/gui_widgets/${WIDGET_PATH}/*.c
src/ui/gui_views/${WIDGET_SUBPATH}/*.c
src/ui/gui_views/${WIDGET_PATH}/*.c
src/ui/gui_chain/${WIDGET_SUBPATH}/*.c
src/ui/gui_chain/${WIDGET_PATH}/*.c
src/ui/gui_wallet/${WIDGET_SUBPATH}/*.c
src/ui/gui_wallet/${WIDGET_PATH}/*.c
src/ui/gui_analyze/${WIDGET_SUBPATH}/*.c
src/ui/gui_analyze/${WIDGET_PATH}/*.c
)

file(GLOB_RECURSE GUI
${GUI_CUSTOM_VIEW_WIDGETS}
"src/ui/gui_assets/*.c"
"src/ui/gui_assets/font/*.c"
"src/ui/gui_assets/abi/*.c"
"src/ui/gui_frame/*.c"
"src/ui/gui_views/*.c"
"src/ui/gui_widgets/*.c"
"src/ui/gui_widgets/setting/*.c"
"src/ui/lv_i18n/*.c"
"src/ui/gui_model/*.c"
"src/ui/gui_analyze/*.c"
"src/ui/gui_chain/*.c"
"src/ui/gui_components/*.c"
"src/ui/wallet/*.c"
)

file(GLOB_RECURSE LVGL
Expand Down Expand Up @@ -267,18 +296,6 @@ if(COMPILE_KEYSTONE)
src/cm_backtrace/fault_handler/gcc/cmb_fault.s
)

if(BTC_ONLY)
set(excluded_directories
src/ui/gui_chain/others
src/ui/gui_widgets/general
src/ui/gui_views/general
src/webusb_protocol/general)
else()
set(excluded_directories
src/ui/gui_views/btc_only
src/ui/gui_widgets/btc_only)
endif()

foreach(directory ${excluded_directories})
file(GLOB_RECURSE excluded_files "${directory}/*")
list(REMOVE_ITEM objsrc ${excluded_files})
Expand Down Expand Up @@ -343,7 +360,7 @@ else()
${UTILS}
${CRYPTO_SLIP39}
)
add_dependencies(${PROJECT_NAME} rust_c)
# add_dependencies(${PROJECT_NAME} rust_c)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2 ${CMAKE_SOURCE_DIR}/ui_simulator/lib/rust-builds/librust_c.a)
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(${PROJECT_NAME} PRIVATE m dl pthread )
Expand Down
3 changes: 2 additions & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SET LANGUAGE_PATH=%CD%\src\ui\lv_i18n
SET LANGUAGE_SCRIPT=py data_loader.py
SET RUST_C_PATH=%CD%\rust\rust_c

SET "build_options=log copy production screen debug format release rebuild btc_only simulator language clean"
SET "build_options=log copy production screen debug format release rebuild btc_only cyberpunk simulator language clean"
FOR %%O IN (%build_options%) DO SET "build_%%O=false"

FOR %%i in (%*) DO (
Expand Down Expand Up @@ -54,6 +54,7 @@ IF "%build_language%"=="true" (
SET cmake_parm=
IF "%build_production%"=="true" SET "cmake_parm=%cmake_parm% -DBUILD_PRODUCTION=true"
IF "%build_btc_only%"=="true" SET "cmake_parm=%cmake_parm% -DBTC_ONLY=true"
IF "%build_cyberpunk%"=="true" SET "cmake_parm=%cmake_parm% -DCYBERPUNK=true"
IF "%build_screen%"=="true" SET "cmake_parm=%cmake_parm% -DENABLE_SCREEN_SHOT=true"
IF "%build_debug%"=="true" SET "cmake_parm=%cmake_parm% -DDEBUG_MEMORY=true"

Expand Down
123 changes: 123 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/bin/bash

set -e
set -o pipefail

BUILD_FOLDER="$(pwd)/build"
BUILD_SIMULATOR_FOLDER="$(pwd)/build_simulator"
TOOLS_FOLDER="$(pwd)/tools"
MAKE_OAT_FILE_PATH="${TOOLS_FOLDER}/ota_file_maker"
MAKE_PADDING_FILE_PATH="${TOOLS_FOLDER}/padding_bin_file"
ASTYLE_PATH="${TOOLS_FOLDER}/AStyle.sh"
PACK_PATH="$(pwd)/pack.sh"
LANGUAGE_PATH="$(pwd)/src/ui/lv_i18n"
LANGUAGE_SCRIPT="python3 data_loader.py"
RUST_C_PATH="$(pwd)/rust/rust_c"

declare -A build_options=(
["log"]=false
["copy"]=false
["production"]=false
["screen"]=false
["debug"]=false
["format"]=false
["release"]=false
["rebuild"]=false
["btc_only"]=false
["cyberpunk"]=false
["simulator"]=false
["language"]=false
["clean"]=false
)

for arg in "$@"; do
if [[ "$arg" == "format" ]]; then
pushd "$TOOLS_FOLDER"
echo "Formatting files..."
bash "$ASTYLE_PATH"
popd
else
echo "Building with option: $arg"
build_options["$arg"]=true
fi
done

echo "Building with options: ${build_options[@]}"

if [[ "${build_options[rebuild]}" == true ]]; then
if [[ -d "$BUILD_FOLDER" ]]; then
rm -rf "$BUILD_FOLDER"
fi
pushd "$RUST_C_PATH"
cargo clean
popd
fi

mkdir -p "$BUILD_FOLDER"

if [[ ! -f "$BUILD_FOLDER/padding_bin_file.py" ]]; then
cp "$MAKE_PADDING_FILE_PATH/padding_bin_file.py" "$BUILD_FOLDER/padding_bin_file.py"
fi

execute_build() {
if [[ "${build_options[language]}" == true ]]; then
pushd "$LANGUAGE_PATH"
$LANGUAGE_SCRIPT
popd
fi

cmake_parm=""
if [[ "${build_options[production]}" == true ]]; then
cmake_parm="${cmake_parm} -DBUILD_PRODUCTION=true"
fi
if [[ "${build_options[btc_only]}" == true ]]; then
cmake_parm="${cmake_parm} -DBTC_ONLY=true"
fi
if [[ "${build_options[cyberpunk]}" == true ]]; then
cmake_parm="${cmake_parm} -DCYBERPUNK=true"
fi
if [[ "${build_options[screen]}" == true ]]; then
cmake_parm="${cmake_parm} -DENABLE_SCREEN_SHOT=true"
fi
if [[ "${build_options[debug]}" == true ]]; then
cmake_parm="${cmake_parm} -DDEBUG_MEMORY=true"
fi

if [[ "${build_options[simulator]}" == true ]]; then
mkdir -p "$BUILD_SIMULATOR_FOLDER"
pushd "$BUILD_SIMULATOR_FOLDER"
cmake -G "Unix Makefiles" -DBUILD_TYPE=Simulator $cmake_parm ..
make -j16
popd
else
pushd "$BUILD_FOLDER"
cmake -G "Unix Makefiles" $cmake_parm ..
if [[ "${build_options[log]}" == true ]]; then
make -j16 > makefile.log 2>&1
else
make -j16
fi
python3 padding_bin_file.py mh1903.bin
popd
fi

if [[ "${build_options[copy]}" == true ]]; then
echo "Generating pillar.bin file..."
pushd "$MAKE_OAT_FILE_PATH"
echo "Generating OTA files..."
bash make_ota_file.sh "$(pwd)/build/pillar.bin"
bash make_ota_file.sh "$(pwd)/build/keystone3.bin"
bash make_ota_file.sh "F:/pillar.bin"
popd
elif [[ "${build_options[release]}" == true ]]; then
pushd "$MAKE_OAT_FILE_PATH"
echo "Generating release files..."
bash make_ota_file.sh "$(pwd)/build/pillar.bin"
bash make_ota_file.sh "$(pwd)/build/keystone3.bin"
popd
elif [[ "${build_options[simulator]}" == true ]]; then
./build/simulator.exe
fi
}

execute_build
Loading
Loading