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

How to provide TARGET_CC/CXX/AR when cross compiling? #165

Closed
Tracked by #163
jasta opened this issue Jan 24, 2023 · 7 comments
Closed
Tracked by #163

How to provide TARGET_CC/CXX/AR when cross compiling? #165

jasta opened this issue Jan 24, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@jasta
Copy link
Contributor

jasta commented Jan 24, 2023

Bug description

Trying to build any crate that utilizes the cc crate is likely to fail because TARGET_CC/CXX/AR (maybe others) are not set. The toolchain will be defaulted to the host cc which isn't expected to work and gives errors about unknown arguments.

  running: "cc" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-march=rv32imc" "-mabi=ilp32" "-mcmodel=medany" "-I" "/media/jasta/data/software/lvgl-rs/lvgl-sys/vendor/lvgl/src" "-I" "/media/jasta/data/software/lvgl-rs/lvgl-sys/vendor" "-I" "/home/jasta/software/cc-broken" "-DLV_CONF_INCLUDE_SIMPLE=1" "-o" "/media/jasta/data/software/cc-broken/target/riscv32imc-esp-espidf/debug/build/lvgl-sys-2a3b0bc869059431/out/8142b73eb685051c-lv_indev.o" "-c" "/media/jasta/data/software/lvgl-rs/lvgl-sys/vendor/lvgl/src/lv_core/lv_indev.c"
  cargo:warning=cc: error: unrecognized argument in option ‘-mabi=ilp32’
  cargo:warning=cc: note: valid arguments to ‘-mabi=’ are: ms sysv
  cargo:warning=cc: error: unrecognized argument in option ‘-mcmodel=medany’
  cargo:warning=cc: note: valid arguments to ‘-mcmodel=’ are: 32 kernel large medium small
  exit status: 1
  • Would you like to work on a fix? Yes, but I don't know how :)

To Reproduce

Steps to reproduce the behavior:

  1. See: Add CC and AR variables of compiler name to generated export script rust-build#61 (comment)

Expected behavior

Unsure exactly, I guess I expect cc and other crates to be able to automatically figure out which toolchain to use somehow, though I don't really know how that's supposed to work normally.

Screenshots

N/A

Environment

  • OS: Ubuntu 22.04
  • espup version: 0.2.5

Additional context

I think this may be a broader problem in the Rust cross compilation ecosystem. Perhaps best we can do is add some notes to the Rust ESP book or troubleshooting section that talk about what to do.

@jasta jasta added the bug Something isn't working label Jan 24, 2023
@jasta
Copy link
Contributor Author

jasta commented Jan 24, 2023

Digging a little deeper, I think cc is confused because we're using ldproxy as the RUSTC_LINKER:

https://github.com/rust-lang/cc-rs/blob/d69bc7db4493685508a1fecab8b98c5de811bd45/src/lib.rs#L2868

It could also be that we're somehow supposed to make use of the CROSS_COMPILE env variable and somehow modify that big list of targets. I'm really not sure.

@jasta jasta closed this as completed Jan 24, 2023
@jasta
Copy link
Contributor Author

jasta commented Jan 24, 2023

Mistakenly closed, sorry :)

@jasta jasta reopened this Jan 24, 2023
@jasta
Copy link
Contributor Author

jasta commented Jan 25, 2023

I discovered that CROSS_COMPILE does indeed work. You need to set CROSS_COMPILE="riscv32-esp-elf" for example to convince cc that it should use that toolchain. Unfortunately what we really need is for .cargo/config to support specifying environment variables on a per target basis.

@jasta
Copy link
Contributor Author

jasta commented Jan 25, 2023

Exploring an option to patch cc-rs to make this automatic...

@jasta
Copy link
Contributor Author

jasta commented Jan 25, 2023

This can be done with rust-lang/cc-rs#776 but I think only for riscv32imc-esp-espidf. The xtensa targets aren't Tier 3 and might not be accepted yet.

@jasta
Copy link
Contributor Author

jasta commented Jan 27, 2023

Closing for now as the cc-rs change has been merged for riscv32imc-esp-espidf. We can revisit adding the xtensa targets later. For now, xtensa targets can work around this with:

CROSS_COMPILE=xtensa-esp32-elf cargo build

@jasta jasta closed this as completed Jan 27, 2023
@pwfff
Copy link

pwfff commented Jun 6, 2023

adding a comment here just to say I ran into this and the above solution worked (as well as the solution I managed to arrive at, which was CC=xtensa-esp32s3-elf-cc cargo build).

also adding the specific error I got here for google SEO:

547165c3df62f629.rlib: error adding symbols: file format not recognized
          collect2: error: ld returned 1 exit status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants