xargo icon indicating copy to clipboard operation
xargo copied to clipboard

Building `alloc` does not work with included compiler_builtins

Open phil-opp opened this issue 7 years ago • 6 comments

The compiler_builtins crate is now explicitly injected. When building the alloc crate via a [dependencies.alloc] key in the Xargo.toml, a “multiple matching crates for compiler_builtins” error occurs. The reason is that alloc defines its own compiler_builtins dependency. Thus compiler_builtins in compiled twice, once as version 0.0.0 and once as version 0.1.0.

phil-opp avatar Apr 10 '18 13:04 phil-opp

With latest xargo and nightly rustc, I saw the same error.

To fix it, I removed all references to compiler_bultins in my Xargo.toml and src/lib.rs.

diff --git a/Xargo.toml b/Xargo.toml
index a16927a..cb49458 100644
--- a/Xargo.toml
+++ b/Xargo.toml
@@ -3,9 +3,3 @@ alloc = {}
 
 [target.x86_64-rxinu.dependencies]
 alloc = {}
-
-[dependencies.core]
-stage = 0
-
-[dependencies.compiler_builtins]
-stage = 1
diff --git a/src/lib.rs b/src/lib.rs
index dae5ba2..dc9ec7f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,7 +4,6 @@
 #![feature(const_fn)]
 #![feature(const_max_value)]
 #![feature(const_unique_new, const_atomic_usize_new)]
-#![feature(compiler_builtins_lib)]
 #![feature(const_fn)]
 #![feature(lang_items)]
 #![feature(naked_functions)]
@@ -25,7 +24,6 @@ extern crate lazy_static;
 extern crate once;
 
 extern crate bit_field;
-extern crate compiler_builtins;
 extern crate linked_list_allocator;
 extern crate multiboot2;
 extern crate rlibc;

Current Xargo.toml

[target.i686-rxinu.dependencies]
alloc = {}

[target.x86_64-rxinu.dependencies]
alloc = {}

robert-w-gries avatar Apr 10 '18 17:04 robert-w-gries

@robert-w-gries That's also what I did.

lachlansneff avatar Apr 10 '18 20:04 lachlansneff

I see that my workaround does not work if you want to use the compiler_builtins mem feature.

My project uses the rlibc crate, which is why I could remove compiler_builtins from my Xargo.toml without issue.

robert-w-gries avatar Apr 10 '18 21:04 robert-w-gries

I created a simplified fork of xargo at rust-osdev/cargo-xbuild, which just always compiles core, compiler_builtins and alloc without configuration ability. The advantage of hard-coding those is that we can hack the alloc compilation so that it uses compiler_builtins with the "mem" feature.

@lachlansneff @robert-w-gries Could you try if this works for you?

phil-opp avatar May 06 '18 08:05 phil-opp

cargo install cargo-xbuild and cargo xbuild --target x86_64-rxinu.json worked without issue for me.

Was there anything else you wanted me to test? I'm not sure if I need to do something more on my end to make sure the following works:

The advantage of hard-coding those is that we can hack the alloc compilation so that it uses compiler_builtins with the "mem" feature.

robert-w-gries avatar May 06 '18 16:05 robert-w-gries

Was there anything else you wanted me to test? I'm not sure if I need to do something more on my end to make sure the following works:

You should be able to remove the rlibc dependency.

phil-opp avatar May 07 '18 09:05 phil-opp