firecracker-microvm / firecracker

Secure and fast microVMs for serverless computing.
http://firecracker-microvm.io
Apache License 2.0
24.53k stars 1.72k forks source link

firecracker compilation issue on openSUSE Tumbleweed x86_64 #3584

Closed paolostivanin closed 1 year ago

paolostivanin commented 1 year ago

While compiling firecracker for openSUSE Tumbleweed x86_64, the compilation fails with:

[   91s]    Compiling bincode v1.3.3
[   92s] error: failed to run custom build command for `userfaultfd-sys v0.4.3`
[   92s] 
[   92s] Caused by:
[   92s]   process didn't exit successfully: `/home/abuild/rust/firecracker/release/build/userfaultfd-sys-f8761062372fd5c8/build-script-build` (exit status: 101)
[   92s]   --- stderr
[   92s]   thread 'main' panicked at '"uffd_msg_union_(unnamed_at_/usr/include/linux/userfaultfd_h_102_2)" is not a valid Ident', /home/abuild/rpmbuild/BUILD/firecracker-1.3.1/vendor/proc-macro2/src/fallback.rs:811:9
[   92s]   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[   92s] warning: build failed, waiting for other jobs to finish...
[  110s] warning: No default seccomp policy for target: x86_64-unknown-linux-gnu. Defaulting to `resources/seccomp/unimplemented.json`.
[  110s] error: Bad exit status from /var/tmp/rpm-tmp.ULCvUw (%build)
[  110s] 
[  110s] RPM build errors:
[  110s]     Bad exit status from /var/tmp/rpm-tmp.ULCvUw (%build)
[  110s] 
[  110s] suse-ws.fritz.box failed "build firecracker.spec" at Fri Mar 31 08:01:27 UTC 2023.

please note that:

Please find attached logs both for Leap 15.5 x86_64 compiling fine and Tumbleweed x86_64 not compiling due to the aforementioned error.

leapOK.txt tumbleweedFAIL.txt

roypat commented 1 year ago

Hey Paolo, thanks for the report!

I've had a quick look at this, and I think this is a bindgen-rs issue. The compilation error happens when the userfaultfd-sys crate uses bindgen-rs to generate rust bindings to linux/userfaultfd.h. I found a similar issue on the bindgen.rs repository that is related to clang changing behavior wrt anonymous type naming (https://github.com/rust-lang/rust-bindgen/issues/2312). In this specific case here, some struct member ends up named uffd_msg_union_(unnamed_at_/usr/include/linux/userfaultfd_h_102_2), and then a derive macro implemented on that struct rightfully complains that that's not a valid identifier. This apparently got patched in bindgen 0.62.0, but userfaultfd-sys is still using 0.60.1.

Could you check if you run into the same error if you only try to compile the userfaultfd crate in the same setup? If so, then userfaultfd-rs needs to update its dependency on bindgen-rs to at least 0.62.0 (and if that also does not fix it, then this is probably a new bindgen bug).

As for an immediate fix, you could try downgrading clang to a version prior to 16, as that's when the change in clang got introduced.

As an aside, I noticed that on Leap you're compiling firecracker 1.2, but on tumbleweed its 1.3.1, is that intended?

paolostivanin commented 1 year ago

Yes, I just started working on packaging 1.3.1 :) first I've gotta push it to TW, then I can forward it to Leap 15.5. Currently, on TW we have 1.2, but that also fails to compile on x86_64.

paolostivanin commented 1 year ago

Could you check if you run into the same error if you only try to compile the userfaultfd crate in the same setup?

Not sure how to do that. I'm kinda new to Rust, so my Cargo knowledge is limited. If you could kindly provide me with a branch that contains this fix, I can simply download it and test whether the compilation works :smile:

As for an immediate fix, you could try downgrading clang to a version prior to 16, as that's when the change in clang got introduced.

Unfortunately, that it's not possible.

roypat commented 1 year ago

Could you check if you run into the same error if you only try to compile the userfaultfd crate in the same setup?

Not sure how to do that. I'm kinda new to Rust, so my Cargo knowledge is limited. If you could kindly provide me with a branch that contains this fix, I can simply download it and test whether the compilation works 😄

So to verify that the issue is indeed in userfaultfd-rs, you can do

git clone https://github.com/bytecodealliance/userfaultfd-rs
cd userfaultfd-rs
cargo build

which should fail with the same error you were getting above.

There is no fixed branch yet that I'm aware of, but the patch for that crate should be

diff --git userfaultfd-sys/Cargo.toml userfaultfd-sys/Cargo.toml
index 840d295..b08dd39 100644
--- userfaultfd-sys/Cargo.toml
+++ userfaultfd-sys/Cargo.toml
@@ -13,7 +13,7 @@ build = "build.rs"
 cfg-if = "^1.0.0"

 [build-dependencies]
-bindgen = { version = "^0.60.1", default-features = false, features = ["runtime"]  }
+bindgen = { version = "^0.64.0", default-features = false, features = ["runtime"]  }
 cc = "1.0"

 [features]

You can try applying that to that repository and run cargo build again. If that works, then the best you can do is submit an issue/PR to userfaultfd to get them to update their bindgen dependency.

Sorry for not checking all this myself btw, but I don't really know how to get my hands on clang 16 easily >.>

paolostivanin commented 1 year ago

thank you, I'll try your solution :)

dianpopa commented 1 year ago

@paolostivanin does the solution provided above work for you?

Thanks!

paolostivanin commented 1 year ago

the issue is fixed with the latest 1.3.2 update, thanks