[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


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
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

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

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 = ...snip... -lntdll

## Warning

This one is a bit tricky, After modifying `PKG_LIBS`, your build should
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
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
to consider giving up your package on oldrel when the CRAN Windows server
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
should be fine if it doesn't overflow in actual. But, I'm not an expert
so please decide at your own risk.

Hope this helps.


[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

	[[alternative HTML version deleted]]

More information about the R-package-devel mailing list