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

Determine link flags by interrogating the Makefile #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion flash-project
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ set -e
--flash_mode dio \
--flash_freq 40m \
--flash_size detect \
0x1000 build/bootloader/bootloader.bin \
0x10000 build/esp-app.bin \
0x8000 build/partitions_singleapp.bin
55 changes: 3 additions & 52 deletions templates/cargo.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,9 @@
target = "xtensa-esp32-none-elf"

[target.xtensa-esp32-none-elf]
linker = "rust-esp-linker"
rustflags = [
"-C", "target-cpu=esp32",
"-C", "save-temps",
"-C", "link-arg=-nostdlib",
# "-C", "link-arg=-nostartfiles",

"-C", "link-arg=-ucall_user_start_cpu0",
"-C", "link-arg=-u__cxa_guard_dummy",
"-C", "link-arg=-u__cxx_fatal_exception",
"-C", "link-arg=-uld_include_panic_highint_hdl",
"-C", "link-arg=-uesp_app_desc",

"-C", "link-arg=-Wl,--gc-sections",
"-C", "link-arg=-Wl,-static",
"-C", "link-arg=-Wl,--start-group",

"-C", "link-arg=-Lbuild/app_update", "-C", "link-arg=-lapp_update",
"-C", "link-arg=-Lbuild/driver", "-C", "link-arg=-ldriver",
"-C", "link-arg=-Lbuild/esp-tls", "-C", "link-arg=-lesp-tls",
"-C", "link-arg=-Lbuild/esp32", "-C", "link-arg=-lesp32",
"-C", "link-arg=esp-idf/components/esp32/libhal.a",
"-C", "link-arg=-Lesp-idf/components/esp32/lib", "-C", "link-arg=-lcore",

"-C", "link-arg=-Lesp-idf/components/esp32/ld",
"-C", "link-arg=-Tesp32_out.ld",
"-C", "link-arg=-Tbuild/esp32/esp32.project.ld",
"-C", "link-arg=-Tesp32.rom.ld",
"-C", "link-arg=-Tesp32.peripherals.ld",
"-C", "link-arg=-Tesp32.rom.libgcc.ld",
"-C", "link-arg=-Tesp32.rom.spiram_incompatible_fns.ld",

"-C", "link-arg=-Lbuild/esp_ringbuf", "-C", "link-arg=-lesp_ringbuf",
"-C", "link-arg=-Lbuild/freertos", "-C", "link-arg=-lfreertos",

"-C", "link-arg=-Wl,--undefined=uxTopUsedPriority",

"-C", "link-arg=-Lbuild/heap", "-C", "link-arg=-lheap",
"-C", "link-arg=-Lbuild/log", "-C", "link-arg=-llog",

"-C", "link-arg=esp-idf/components/newlib/lib/libc.a",
"-C", "link-arg=esp-idf/components/newlib/lib/libm.a",

"-C", "link-arg=-Lbuild/newlib", "-C", "link-arg=-lnewlib",
"-C", "link-arg=-Lbuild/pthread", "-C", "link-arg=-lpthread",
"-C", "link-arg=-Lbuild/soc", "-C", "link-arg=-lsoc",
"-C", "link-arg=-Lbuild/spi_flash", "-C", "link-arg=-lspi_flash",
"-C", "link-arg=-Lbuild/vfs", "-C", "link-arg=-lvfs",
"-C", "link-arg=-Lbuild/xtensa-debug-module", "-C", "link-arg=-lxtensa-debug-module",

"-C", "link-arg=-lgcc",
"-C", "link-arg=-lstdc++",
"-C", "link-arg=-lgcov",
"-C", "link-arg=-Wl,--end-group",
"-C", "link-arg=-Wl,-EL",
"-C", "save-temps"
]

12 changes: 12 additions & 0 deletions xbuild-project
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@

set -e

get_make_var() {
var=$1
mkfile=$(mktemp /home/project/build/linker-XXXXXXXXXX.mk)
cp /home/project/Makefile "$mkfile"
echo 'print-%: ; @echo get-make-var: $($*)' >> "$mkfile"
value=$(make "print-$var" -f "$mkfile" BUILD_DIR_BASE="/home/project/build" | grep -F 'get-make-var: ' | cut -d' ' -f2-)
echo "$value"
}

LDFLAGS="$(get_make_var LDFLAGS)"
export RUSTFLAGS="-C target-cpu=esp32 -C save-temps $(echo "$LDFLAGS" | sed 's/[^ ]* */-C link-arg=&/g')"

cargo +xtensa xbuild --target "${XARGO_TARGET:-xtensa-esp32-none-elf}" --release