Skip to content

Commit 00bf75d

Browse files
build(cross-build): add support for debug builds
1 parent 28c5a00 commit 00bf75d

2 files changed

Lines changed: 42 additions & 10 deletions

File tree

.github/workflows/crossplatform.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ jobs:
158158
fi
159159
export CLANG=/usr/bin/clang-20
160160
export CLANGXX=/usr/bin/clang++-20
161-
./cross-build/build.sh ${{ matrix.target }}
161+
./cross-build/build.sh ${{ matrix.target }} --debug
162162
163163
- name: Build binaries (cross-rs)
164164
if: matrix.cross-rs == true && matrix.cross-build != true

cross-build/build.sh

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Options:
3535
-s, --sysroot-dir DIR Custom sysroot directory (default: auto-detect)
3636
-o, --output-dir DIR Output directory (default: dist/)
3737
-b, --bench-duration SEC Benchmark duration for PGO (default: 30)
38+
-d, --debug Enable debug build (default: release)
3839
-h, --help Show this help message
3940
4041
Examples:
@@ -45,6 +46,8 @@ Examples:
4546
Environment variables:
4647
RUSTFLAGS Extra Rust compiler flags (will be extended for PGO)
4748
SYSROOT_DIR Override sysroot directory
49+
CLANG Override clang compiler (default: auto-detect)
50+
CLANGXX Override clang++ compiler (default: auto-detect)
4851
EOF
4952
}
5053

@@ -604,6 +607,7 @@ pgo_build() {
604607
local target="$1"
605608
local pgo_data_dir="/tmp/ferron-pgo-data-$$"
606609
local bench_duration="$2"
610+
local debug="$3"
607611
608612
log_step "Phase 1: Building with PGO instrumentation"
609613
@@ -612,12 +616,20 @@ pgo_build() {
612616
local instrument_rustflags="-Cprofile-generate=${pgo_data_dir}"
613617
# Append to (not replace) the existing RUSTFLAGS so target-specific flags
614618
# set by setup_env_* (e.g. musl's -lc++abi / -L<sysroot>/lib) are preserved.
615-
RUSTFLAGS="${RUSTFLAGS:-} ${instrument_rustflags}" cargo build --release --target "${target}" \
616-
--manifest-path "${PROJECT_ROOT}/Cargo.toml"
619+
if [[ "${debug}" == "true" ]]; then
620+
RUSTFLAGS="${RUSTFLAGS:-} ${instrument_rustflags}" cargo build --target "${target}" \
621+
--manifest-path "${PROJECT_ROOT}/Cargo.toml"
622+
else
623+
RUSTFLAGS="${RUSTFLAGS:-} ${instrument_rustflags}" cargo build --release --target "${target}" \
624+
--manifest-path "${PROJECT_ROOT}/Cargo.toml"
625+
fi
617626
618627
log_step "Phase 2: Running PGO training benchmarks"
619628
620629
local built_binary="${PROJECT_ROOT}/target/${target}/release/ferron"
630+
if [[ "${debug}" == "true" ]]; then
631+
built_binary="${PROJECT_ROOT}/target/${target}/debug/ferron"
632+
fi
621633
if [[ ! -f "${built_binary}" ]]; then
622634
log_error "Built binary not found: ${built_binary}"
623635
return 1
@@ -678,8 +690,13 @@ pgo_build() {
678690
679691
local optimize_rustflags="-Cprofile-use=${pgo_data_dir}/merged.profdata"
680692
# Append to (not replace) the existing RUSTFLAGS — see phase 1 note.
681-
RUSTFLAGS="${RUSTFLAGS:-} ${optimize_rustflags}" cargo build --release --target "${target}" \
682-
--manifest-path "${PROJECT_ROOT}/Cargo.toml"
693+
if [[ "${debug}" == "true" ]]; then
694+
RUSTFLAGS="${RUSTFLAGS:-} ${optimize_rustflags}" cargo build --target "${target}" \
695+
--manifest-path "${PROJECT_ROOT}/Cargo.toml"
696+
else
697+
RUSTFLAGS="${RUSTFLAGS:-} ${optimize_rustflags}" cargo build --release --target "${target}" \
698+
--manifest-path "${PROJECT_ROOT}/Cargo.toml"
699+
fi
683700
684701
log_info "PGO build complete"
685702
@@ -692,19 +709,29 @@ pgo_build() {
692709
693710
regular_build() {
694711
local target="$1"
712+
local debug="$2"
695713
696714
log_step "Building Ferron"
697715
698-
cargo build --release --target "${target}" \
699-
--manifest-path "${PROJECT_ROOT}/Cargo.toml"
716+
if [[ "${debug}" == "true" ]]; then
717+
cargo build --target "${target}" \
718+
--manifest-path "${PROJECT_ROOT}/Cargo.toml"
719+
else
720+
cargo build --release --target "${target}" \
721+
--manifest-path "${PROJECT_ROOT}/Cargo.toml"
722+
fi
700723
701724
log_info "Build complete"
702725
}
703726
704727
copy_binaries() {
705728
local target="$1"
706729
local output_dir="$2"
730+
local debug="$3"
707731
local target_dir="${PROJECT_ROOT}/target/${target}/release"
732+
if [[ "${debug}" == "true" ]]; then
733+
target_dir="${PROJECT_ROOT}/target/${target}/debug"
734+
fi
708735
local binaries=(
709736
"ferron"
710737
"ferron-fmt"
@@ -738,6 +765,7 @@ copy_binaries() {
738765
main() {
739766
local target=""
740767
local pgo=false
768+
local debug=false
741769
local sysroot_dir=""
742770
local output_dir="${PROJECT_ROOT}/dist"
743771
local bench_duration=30
@@ -764,6 +792,10 @@ main() {
764792
usage
765793
exit 0
766794
;;
795+
-d | --debug)
796+
debug=true
797+
shift
798+
;;
767799
-*)
768800
log_error "Unknown option: $1"
769801
usage >&2
@@ -838,15 +870,15 @@ main() {
838870
839871
# Build
840872
if [[ "${pgo}" == "true" ]]; then
841-
pgo_build "${target}" "${bench_duration}"
873+
pgo_build "${target}" "${bench_duration}" "${debug}"
842874
else
843-
regular_build "${target}"
875+
regular_build "${target}" "${debug}"
844876
fi
845877
846878
# Copy binaries
847879
local target_output="${output_dir}/${target}"
848880
mkdir -p "${target_output}"
849-
copy_binaries "${target}" "${target_output}"
881+
copy_binaries "${target}" "${target_output}" "${debug}"
850882
851883
log_step "Build Summary"
852884
log_info "Target: ${target}"

0 commit comments

Comments
 (0)