tsgates / rust.ko

A minimal Linux kernel module written in rust.
894 stars 66 forks source link

Compilation error: Could not find specification for target "x86_64-unknown-none-gnu" #28

Open frol opened 6 years ago

frol commented 6 years ago
$ rustup run nightly make KERNEL_BUILD_PATH=/lib/modules/4.17.11-arch1/build/ CARGO=/home/frol/.cargo/bin/xargo
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --sysroot /home/frol/.xargo -Z force-unstable-if-unmarked --target x86_64-unknown-none-gnu --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro` (exit code: 1)
--- stderr
error: Error loading target specification: Field target-c-int-width in target specification is required
  |
  = help: Use `--print target-list` for a list of built-in targets

I have updated the x86_64-unknown-none-gnu.json file with the version from rust-barebones-kernel, but still cannot get through error:

$ rustup run nightly make KERNEL_BUILD_PATH=/lib/modules/4.17.11-arch1/build/ CARGO=/home/frol/.cargo/bin/xargo
   Compiling core v0.1.0 (https://github.com/phil-opp/nightly-libcore.git#54571deb)
   Compiling kernel32-sys v0.2.2
   Compiling log v0.4.3
   Compiling clang-sys v0.5.4
error: Error loading target specification: Could not find specification for target "x86_64-unknown-none-gnu"
  |
  = help: Use `--print target-list` for a list of built-in targets

error: Could not compile `core`.
warning: build failed, waiting for other jobs to finish...
error: build failed
make[2]: *** [/mnt/storage/projects/linux-kernel-basecamp/rust.ko/build/Makefile:46: /mnt/storage/projects/linux-kernel-basecamp/rust.ko/build/libhello.a] Error 101
make[1]: *** [Makefile:1571: _module_/mnt/storage/projects/linux-kernel-basecamp/rust.ko/build] Error 2
make: *** [Makefile:36: all] Error 2

Can anyone help me?

wfraser commented 5 years ago

I got past this error by adding RUST_TARGET_PATH='${BASE_DIR}' as an additional environment variable to the cargo command in kbuild.mk on line 46. It appears there's a bug in Cargo where when it changes directory to build other crates, it loses where to find the target specification, so you have to set that variable to make it remember. See https://github.com/rust-lang/cargo/issues/4905

But after fixing that, I get a ton of errors from the nightly-libcore crate, which it seems has not been kept up to date.

wfraser commented 5 years ago

Ah, it seems the proper way going forward is to use Xargo instead of Cargo and this nightly-libcore hack. Xargo takes care of building libcore for the proper target for you. I've done a bit of work on my fork (https://github.com/wfraser/rust.ko) that involves this, and also updating the bindgen version used, among other things, that gets it building on the current nightly rustc.

Skarlett commented 5 years ago

Is this fixed yet?