Closed BD103 closed 1 month ago
Linux checked and working :heavy_check_mark:
Not working on Windows:
This is my target/debug
dir:
After lots of research, turns out this isn't necessary for dev builds. All you need to do is run rustup run nightly-2024-08-21 ./target/debug/bevy_lint_driver
, and it will automatically handle all of the environment setup. Closing!
For a story-driven rant on how I came across this solution, see this chain of posts.
Hi! I spent a lot of my time drafting #32 trying to fix
bevy_lint_driver
's linking issues, but I've finally found a solution that works most of the time.The problem
bevy_lint_driver
, the program that actually registers the lints into the compiler, dynamically links tolibrustc_driver-*.so
. This is perfectly fine with running it through Cargo and theRUSTC_WORKSPACE_WRAPPER
environmental variable, but falls apart when run by itself.Namely, calling
./target/debug/bevy_lint_driver
directly fails with a dynamic linking error:When running it through Cargo, it sets the
LD_LIBRARY_PATH
variable so that the dynamic linker can discoverlibrustc_driver.so
. This variable is present, unfortunately, when running it alone.This becomes a problem for two of my use-cases of the driver:
rustc
is a new codebase that I've never worked on before, I'm using a debugger to figure out what code gets run.ui_test
callsrustc
directly, notcargo
, so I need to configure it to callbevy_lint_driver
directly. See the problem?While it is theoretically possible to set
LD_LIBRARY_PATH
for both of these, I struggled to get either of them to work. If you manage to do so, please let me know!The solution
It is possible to hardcode a dynamic linker search path using the
-rpath
linker flag. To do this, I created a build script that usesrustup
to locatelibrustc_driver.so
and emit the proper flags. It only runs upon first run and wheneverbuild.rs
is changed, so this is really cheap for incremental builds.I heavily commented the entire thing, so take a look! The two biggest drawbacks to this approach are:
/Users/appleseedj/...
into the produced binary.)I'm willing to accept these costs for the time being, as it means I will actually be able to start writing lints and stop finnicking with old and complicated linker details.
Testing
This should be generally platform-compatible, but I will need help testing this. It works on:
To test, please run:
It should print a help screen if everything worked correctly. If it didn't, please paste the error message and I'll try figuring out what went wrong. Thanks!
In the future
I hope for this solution to be temporary. In the future I want to build
rustc_driver
from scratch when release mode is enabled, so that the outputted binary is truly portable. That's for another PR, though!