[R-pkg-devel] Rust 1.70 and build failures on Windows

Hiroaki Yutani yut@n|@|n| @end|ng |rom gm@||@com
Thu Jun 8 11:06:46 CEST 2023


Hi,

This is a quick notice for developers of R packages using Rust.

Rust 1.70 was released on June 1st, 2023 [1]. If you use Rust in your R
package,
you'll probably start to see an error and a warning on the final linking
step of
Windows builds.

## Error

The first thing you'll notice is that linking fails with errors like this
one:

    ...snip...\std\src\sys\windows/handle.rs:290: undefined reference to
`NtWriteFile'

This is because Rust 1.70 started to use several Windows APIs defined in
NTDLL.DLL [2]. So, this can be easily fixed by adding `-ltdll` to
`PKG_LIBS`.

    PKG_LIBS = ...snip... -lntdll


## Warning

This one is a bit tricky, After modifying `PKG_LIBS`, your build should
succeed,
but you might or might not see a lot of warnings like this one:

    Warning: corrupt .drectve at end of def file

This is because Rust 1.70 upgraded LLVM to version 16, and LLVM generates a
binary containing directives that only the very latest version (2.40) of GNU
linker can understand [3]. What's fortunate is that the latest Rtools43 uses
binutils 2.40, so this warning won't happen if you target only R >= 4.3.
However, the following cases might be a problem:

    1. On R < 4.3
    2. On R >= 4.3 with outdated Rtools43 (currently, it's the case on
GitHub Actions [4])

Unfortunately, it seems there's no option to suppress this warning, so
there's
no way to save `R CMD check` from failing if you run it with `--as-cran`. In
other words, if you are a maintainer of some R package on CRAN, you might
need
to consider giving up your package on oldrel when the CRAN Windows server
upgrades
Rust (I heard the current installed version is 1.69, but I'm not sure).

For non-CRAN packages, I think you can ignore the warnings. The directive
is to
reduce the number of exported symbols in order to prevent overflow [5], so
it
should be fine if it doesn't overflow in actual. But, I'm not an expert
here,
so please decide at your own risk.

Hope this helps.

Best,
Yutani

[1]: https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html
[2]: https://en.wikipedia.org/wiki/Microsoft_Windows_library_files#NTDLL.DLL
[3]: https://github.com/rust-lang/rust/issues/112368#issuecomment-1581917714
[4]: https://github.com/r-lib/actions/issues/734
[5]:
https://github.com/llvm/llvm-project/commit/c5b3de6745c37dd991430b9b88ff97c35b6fc455

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list