Skip to content

ci: force GNU ld on Linux to fix -ljvm linker error#4024

Merged
mbutrovich merged 2 commits intoapache:mainfrom
andygrove:fix-ci-ljvm
Apr 22, 2026
Merged

ci: force GNU ld on Linux to fix -ljvm linker error#4024
mbutrovich merged 2 commits intoapache:mainfrom
andygrove:fix-ci-ljvm

Conversation

@andygrove
Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #.

Rationale for this change

Linux CI has been failing on main since ~2026-04-21 20:55 UTC on every
PR with:

rust-lld: error: unable to find library -ljvm
collect2: error: ld returned 1 exit status

The failure reproduces on main at cae101e80 and every later commit,
across PR Build (Linux), Spark SQL Tests, and Iceberg Spark SQL Tests workflows. None of the commits in that window touch native code
or build scripts, so the regression came from the environment.

Rust's stable channel (used by the workflows) released a version
during that window that defaults to rust-lld as the linker on
x86_64-unknown-linux-gnu. The failing linker command clearly shows
-fuse-ld=lld. rust-lld cannot resolve -ljvm against the Zulu
JDK 17 layout that actions/setup-java@v4 installs under
/__t/Java_Zulu_jdk/17.0.18-8/x64/lib/server/ — GNU ld.bfd resolves
it fine.

What changes are included in this PR?

Adds -Clink-arg=-fuse-ld=bfd to RUSTFLAGS in the three Linux CI
workflows: pr_build_linux.yml, spark_sql_test.yml, and
iceberg_spark_test.yml.

  • Set at workflow-level env: so every cargo invocation (including
    those inside the composite rust-test action, which has no explicit
    RUSTFLAGS) picks up GNU ld.
  • Extended the existing step-level RUSTFLAGS: "-Ctarget-cpu=x86-64-v3"
    values to include the same flag, because step-level env replaces
    workflow-level env rather than appending.

macOS CI is also failing but with a different root cause
(ld: library 'jvm' not found, path to Zulu does not exist on the
runner). That is a separate issue and is not addressed here.

How are these changes tested?

By running the affected workflows on this PR. If the Linux Build Native Library, ubuntu-latest/rust-test, Spark SQL Tests, and
Iceberg Spark SQL Tests jobs all reach a normal pass/fail state
instead of failing at the linker, the fix is confirmed.

Recent Rust stable defaults to rust-lld as the linker on
x86_64-unknown-linux-gnu. rust-lld cannot resolve -ljvm against the
Zulu JDK layout installed by actions/setup-java, producing:

    rust-lld: error: unable to find library -ljvm

GNU ld resolves it fine. Add -Clink-arg=-fuse-ld=bfd via workflow-level
RUSTFLAGS so every cargo invocation in Linux CI picks GNU ld, and
extend the per-step RUSTFLAGS values that already set -Ctarget-cpu to
include the same flag (step-level env overrides workflow-level).
The macOS Build Native Library job fails with:

    ld: warning: search path '.../Java_Zulu_jdk/17.0.18-8/aarch64/lib/server' not found
    ld: library 'jvm' not found

native/fs-hdfs/build.rs resolves JAVA_HOME at build time and emits
`cargo:rustc-link-search=native=$JAVA_HOME/lib/server` plus a
`-Wl,-rpath,$JAVA_HOME/lib/server` link arg. Those paths are baked into
the compiled rlib. Because the build script does not declare any
`rerun-if-env-changed=JAVA_HOME`, Cargo has no input that lets it
detect a JDK swap, and a cache restored from a previous run (where
setup-java installed a different Zulu patch version) keeps the stale
paths.

Two changes:

- native/fs-hdfs/build.rs: add `cargo:rerun-if-env-changed=JAVA_HOME`
  so Cargo reruns the build script and refreshes link args whenever
  the resolved JDK changes. This is the robust fix and applies on
  every host, not just CI.

- .github/workflows/pr_build_macos.yml: bump the cache key prefix to
  `cargo-ci-v2` so the existing macOS cache, built against a JDK path
  that no longer exists on the runner, is discarded once. After this
  one-shot bust, the build.rs change handles future JDK updates on
  its own.
Copy link
Copy Markdown
Contributor

@parthchandra parthchandra left a comment

Choose a reason for hiding this comment

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

approved. pending ci

@mbutrovich mbutrovich merged commit 9986587 into apache:main Apr 22, 2026
133 checks passed
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.

4 participants