Skip to content

Commit 234c23b

Browse files
implement rust flag checking logic
1 parent 62b6a2e commit 234c23b

File tree

3 files changed

+58
-39
lines changed

3 files changed

+58
-39
lines changed

config/forbidden-flags.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"PRODUCTION_BUILD=0"
77
],
88
"rust":[
9-
"TBD"
9+
"debug = true"
1010
]
1111
}
1212
}

scripts/check_all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ call_step() {
218218
COMMAND="python3 ${DATABASE_DIR}/scripts/app_load_params_check.py --database_path ${DATABASE_DIR}/app-load-params-db.json --app_manifests_path ${MANIFEST_DIR}"
219219
;;
220220
"makefile")
221-
COMMAND="${dirName}/check_makefile.sh ${APP_DIR} ${REPO_NAME} ${MANIFEST_DIR} ${WORKFLOWS_DIR} ${TARGET}"
221+
COMMAND="${dirName}/check_makefile.sh ${APP_DIR} ${REPO_NAME} ${MANIFEST_DIR} ${WORKFLOWS_DIR} ${IS_RUST} ${TARGET}"
222222
;;
223223
"readme")
224224
COMMAND="${dirName}/check_readme.sh ${APP_DIR} ${REPO_NAME}"

scripts/check_makefile.sh

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ main() (
1111
repo_name="$2"
1212
manifests_dir="$3"
1313
workflows_dir="$4"
14-
target="$5"
14+
is_rust="$5"
15+
target="$6"
1516

1617
declare -A variants_array
1718
declare -A appnames_array
@@ -95,44 +96,62 @@ main() (
9596

9697
# check if there are no forbidden compilation flags (e.g. debug flags)
9798
forbidden_flags_file="${workflows_dir}/config/forbidden-flags.json"
98-
forbidden_flags=$(jq -r '.forbidden.c[]' "$forbidden_flags_file")
99-
100-
entrypoint_filepath=$(grep -rP \
101-
--exclude-dir='deps' \
102-
--exclude-dir='tests' \
103-
--exclude-dir='vendor' \
104-
--include='*.c' \
105-
'\b(app_)?main\s*\([^)]*\)' . | cut -d':' -f1 | head -n1)
106-
entrypoint_filepath=${entrypoint_filepath#./}
107-
entrypoint_filepath=${entrypoint_filepath%.c}.o
108-
109-
build_dir=$(ledger-manifest -ob ledger_app.toml)
110-
if [ -n "${build_dir}" ]; then
111-
for cur_manifest in $manifests_list; do
112-
for variant in "${!variants_array[@]}"; do
113-
build_target=$(jq -r ".VARIANTS.${variant}.TARGET" "${cur_manifest}")
114-
eval "BOLOS_SDK=\$$(echo "${build_target/s2/sp}" | tr '[:lower:]' '[:upper:]')_SDK"
115-
116-
log_info "Trying to make --dry-run for rule build/${build_target}/obj/app/${entrypoint_filepath}. Using $BOLOS_SDK"
117-
118-
make -C "${build_dir}" \
119-
BOLOS_SDK="${BOLOS_SDK}" \
120-
--dry-run build/"${build_target}"/obj/app/"${entrypoint_filepath}" 2>&1 | tee build_dry_run_output.txt
121-
122-
for forbidden_flag in $forbidden_flags; do
123-
log_info "Checking for forbidden flag $forbidden_flag"
124-
if grep -q "$forbidden_flag" build_dry_run_output.txt; then
125-
log_error_no_header "Detected forbidden flag $forbidden_flag in build output."
126-
error=1
127-
else
128-
log_info "Did not find forbidden flag $forbidden_flag in build output."
129-
fi
99+
100+
if [[ ${is_rust} == true ]]; then
101+
echo "$RUSTFLAGS" > env_rustflags.txt
102+
103+
forbidden_flags=$(jq -r '.forbidden.rust[]' "$forbidden_flags_file")
104+
105+
while IFS= read -r forbidden_flag; do
106+
echo "Checking flag $forbidden_flag"
107+
if grep -q "$forbidden_flag" Cargo.toml .cargo/config.toml env_rustflags.txt; then
108+
log_error_no_header "Detected forbidden flag $forbidden_flag in build output."
109+
error=1
110+
else
111+
log_info "Did not find forbidden flag $forbidden_flag in build output."
112+
fi
113+
done <<< "$forbidden_flags"
114+
else
115+
forbidden_flags=$(jq -r '.forbidden.c[]' "$forbidden_flags_file")
116+
117+
entrypoint_filepath=$(grep -rP \
118+
--exclude-dir='deps' \
119+
--exclude-dir='tests' \
120+
--exclude-dir='vendor' \
121+
--include='*.c' \
122+
'\b(app_)?main\s*\([^)]*\)' . | cut -d':' -f1 | head -n1)
123+
entrypoint_filepath=${entrypoint_filepath#./}
124+
entrypoint_filepath=${entrypoint_filepath%.c}.o
125+
126+
build_dir=$(ledger-manifest -ob ledger_app.toml)
127+
if [ -n "${build_dir}" ]; then
128+
for cur_manifest in $manifests_list; do
129+
for variant in "${!variants_array[@]}"; do
130+
build_target=$(jq -r ".VARIANTS.${variant}.TARGET" "${cur_manifest}")
131+
eval "BOLOS_SDK=\$$(echo "${build_target/s2/sp}" | tr '[:lower:]' '[:upper:]')_SDK"
132+
133+
log_info "Trying to make --dry-run for rule build/${build_target}/obj/app/${entrypoint_filepath}. Using $BOLOS_SDK"
134+
135+
make -C "${build_dir}" \
136+
BOLOS_SDK="${BOLOS_SDK}" \
137+
--dry-run build/"${build_target}"/obj/app/"${entrypoint_filepath}" 2>&1 | tee build_dry_run_output.txt
138+
139+
for forbidden_flag in $forbidden_flags; do
140+
log_info "Checking for forbidden flag $forbidden_flag"
141+
if grep -q "$forbidden_flag" build_dry_run_output.txt; then
142+
log_error_no_header "Detected forbidden flag $forbidden_flag in build output."
143+
error=1
144+
else
145+
log_info "Did not find forbidden flag $forbidden_flag in build output."
146+
fi
147+
done
130148
done
131149
done
132-
done
133-
else
134-
log_error_no_header "build directory not found in ledger_app.toml!" >&2
135-
error=1
150+
else
151+
log_error_no_header "build directory not found in ledger_app.toml!" >&2
152+
error=1
153+
fi
154+
136155
fi
137156

138157
if [[ error -eq 0 ]]; then

0 commit comments

Comments
 (0)