Skip to content

ci: add riscv64 release binary via cross-rs#9228

Open
gounthar wants to merge 1 commit intojj-vcs:mainfrom
gounthar:ci/add-riscv64-cross
Open

ci: add riscv64 release binary via cross-rs#9228
gounthar wants to merge 1 commit intojj-vcs:mainfrom
gounthar:ci/add-riscv64-cross

Conversation

@gounthar
Copy link
Copy Markdown

Adds riscv64gc-unknown-linux-musl to the release matrix using cross-rs for cross-compilation on a standard ubuntu-24.04 runner, as discussed in #9183.

Changes:

  • Add linux-riscv64-musl to the build matrix with use_cross: true
  • Install cross before the build step (only for riscv64)
  • Use cross build instead of cargo build for riscv64; all other targets are unchanged

Closes #9183

@gounthar gounthar requested a review from a team as a code owner March 31, 2026 09:41
@PhilipMetzger
Copy link
Copy Markdown
Contributor

please move the Closes line into the commit description to adhere to our commit style.

@gounthar gounthar force-pushed the ci/add-riscv64-cross branch from dd16a95 to f4bfc16 Compare March 31, 2026 15:31
@gounthar
Copy link
Copy Markdown
Author

Done, moved the Closes line into the commit description. Thanks for the heads-up on the style.

@OctopusET
Copy link
Copy Markdown

I believe release version of cross-rs (https://github.com/cross-rs/cross/releases/tag/v0.2.5) doesn't support some targets.
sharkdp/bat#3533

@gounthar gounthar force-pushed the ci/add-riscv64-cross branch from f4bfc16 to ba41a78 Compare March 31, 2026 18:13
@gounthar
Copy link
Copy Markdown
Author

gounthar commented Mar 31, 2026

Good catch, thank you! I've updated to install cross from git at a pinned commit (f86fd03), following the same approach as sharkdp/bat#3533. I should have checked the released version's target support before submitting.

@gounthar gounthar force-pushed the ci/add-riscv64-cross branch from ba41a78 to 71269a5 Compare March 31, 2026 20:20
@gounthar
Copy link
Copy Markdown
Author

gounthar commented Mar 31, 2026

Thanks for the pointer. Moved the change to binaries.yml and reverted release.yml. Build is running on the fork's main now: https://github.com/gounthar/jj/actions/runs/23817622745

@thoughtpolice
Copy link
Copy Markdown
Member

thoughtpolice commented Mar 31, 2026

Thank you! Looks like it worked, but the binary itself is still dynamically linked:

> file jj
jj: ELF 64-bit LSB pie executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-riscv64.so.1, not stripped

Perhaps this is something to do with musl riscv? Or cross-rs? I'm not sure why static linking wouldn't be the default here, but we should preserve this behavior here too (a good example of why I wanted to produce nightly binaries and not releases yet!)

@gounthar
Copy link
Copy Markdown
Author

gounthar commented Mar 31, 2026

Thanks for checking. 😊
I think that is the cross-rs toolchain for riscv64gc-unknown-linux-musl not defaulting to static linking, unlike native musl builds where musl-gcc links statically by default. 🤷

I should have verified the binary type before submitting. I just pushed a fix: it adds -C target-feature=+crt-static via RUSTFLAGS for that matrix entry, which should produce a fully static binary matching the x86_64-musl and aarch64-musl outputs.

Sorry for the oversight.

@PhilipMetzger
Copy link
Copy Markdown
Contributor

You can squash the second commit into the first one, as we generally don't add commits to address reviews. Thanks.

Add riscv64gc-unknown-linux-musl to the binaries.yml matrix using
cross-rs for cross-compilation on a standard ubuntu-24.04 runner.

Installs cross from git at a pinned commit (f86fd03) since the
released v0.2.5 does not include riscv64gc-unknown-linux-musl
support. Uses cross in place of cargo for the riscv64 build;
all other targets are unchanged.

The cross-rs toolchain for this target does not default to static
linking; set RUSTFLAGS=-C target-feature=+crt-static via a per-matrix
rustflags field so the binary is fully statically linked, matching the
x86_64-musl and aarch64-musl outputs.

Closes jj-vcs#9183

Signed-off-by: Bruno Verachten <[email protected]>
@gounthar gounthar force-pushed the ci/add-riscv64-cross branch from 6ed424e to 2438dd7 Compare March 31, 2026 21:23
@gounthar
Copy link
Copy Markdown
Author

gounthar commented Mar 31, 2026

Done, squashed both commits into one. The static linking fix and the Closes line are now part of the original commit. Thanks for the guidance. 🙏

@thoughtpolice
Copy link
Copy Markdown
Member

Would you mind pushing to your repo once more and getting a static binary out, just so we can do a double check? Thanks.

Comment on lines +33 to +34
use_cross: true
rustflags: "-C target-feature=+crt-static"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gounthar
Copy link
Copy Markdown
Author

gounthar commented Apr 5, 2026

Pushed the squashed commit (with RUSTFLAGS=-C target-feature=+crt-static) to the fork's main. Build running: https://github.com/gounthar/jj/actions/runs/23999598196

@gounthar
Copy link
Copy Markdown
Author

gounthar commented Apr 5, 2026

Build passed; linux-riscv64-musl job succeeded: https://github.com/gounthar/jj/actions/runs/23999598196/job/69993388910

Could you download the artifact and verify file jj shows statically linked?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR: Add riscv64 to release binaries

4 participants