Skip to content

*-musl cross builds fail on proc_macro #8

@drozdziak1

Description

@drozdziak1

Steps to reproduce

The issue happens in the proc-macro2 crate on which we indirectly depend. serde depends on it, so we probably won't get away with "dependency amputation". For just reproducing the issue:

  1. Enter althea-firmware
  2. Open roles/prepare-config/defaults/main.yml
  3. Swap out the entry in feeds_list to src-git althea https://github.com/drozdziak1/althea-packages.git;proc-macro-debug-trash
  4. Start the build with any of the defined targets - ansible-playbook should exit with an error
  5. cd build/ to investigate
  6. Rebuild with make -j1 package/althea-rust-binaries/compile V=s to see the full build output
    Steps 1-5. need to be done only once and as long as you don't swap out the althea-pachages to use you only need to do 6. in order to rebuild.

To experiment with our OpenWrt package definition Makefile (This requires doing the steps from the list above):

  1. Clone this and check out branch proc-macro-debug-trash
  2. Get back to althea-firmware and again open roles/prepare-config/defaults/main.yml
  3. This time swap the entry out for src-link althea </full/path/to/where/you/cloned/althea-packages>
  4. cd build/
  5. scripts/feeds uninstall althea-rust-binaries
  6. scripts/feeds uninstall althea-babeld
  7. scripts/feeds uninstall generate-ipv6-address
  8. cd .. back to althea-firmware root
  9. do steps 4-6 from the first list
    Now changes in althea/althea-rust-binaries/Makefile should be immediately applied to the firmware build upon rebuilding (step 6. from the first list in althea-firmware/build)

To experiment with althea_rs in the cross build (This requires doing the steps from the list above):

  1. Clone this
  2. git checkout -b proc-macro-debug-trash to create a disposable trash branch to experiment in
  3. cd into the path where your copy of althea-packages checked out at proc-macro-debug-trash is
  4. open althea/althea-rust-binaries/Makefile
  5. Change PKG_SOURCE_VERSION to proc-macro-debug-trash
  6. Change PKG_SOURCE_URL to the full path to the copy of althea_rs that you just cloned
  7. Do steps 4-6 from the first list
    Now althea-firmware should've built althea_rs using the copy you cloned in step 1. After making a change in your local althea_rs commit it to the proc-macro-debug-trash branch and do rm -rf dl/althea-rust-binaries* in althea-firmware/build. Now you can rebuild (step 6 from the first list) and see the effect.

Expected result

The build succeeds and installs rita and guac-light-client in the firmware

What's actually happening

The cross build for *-musl targets fails because a proc_macro crate cannot be found, presently while building a proc-macro2 crate.

The underlying issue

This seems to be a flaw in Rust itself as only musl targets are ever affected regardless of whether we use OpenWrt or not or whether we build althea_rs or anything else that uses proc_macro (check out the minimal test case below). The problem is that the procedural macro crate is a dynamically linked library. For some reason this messes up builds against the musl libc implementation. See Links for more information.

Minimal test case

Apart from the relatively complicated reproduction steps above, it's possible to trivially reproduce the underlying issue outside the OpenWrt cross-build:

  1. Create a new cargo library project with cargo new blah
  2. Open blah/src/lib.rs and add extern crate proc_macro; on top
  3. Run cargo build --target <some -musl target>

The build should fail on proc_macro being not found and at the same time compile normally without --target <some -musl target> or a -gnu target. If the proc_macro issue was not present, the build should complain about the linker being unspecified. OpenWrt deals with this by supplying all necessary cross environment information through env variables.

Links

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions