Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving from rustup/nightlies to standard rust #28

Open
jejb opened this issue Dec 20, 2022 · 7 comments
Open

Moving from rustup/nightlies to standard rust #28

jejb opened this issue Dec 20, 2022 · 7 comments

Comments

@jejb
Copy link

jejb commented Dec 20, 2022

The SVSM cannot be packaged by any distribution until it can be built by a standard and released version of rust. How far away from this are we? The main reason I thought we needed nightlies was asm() which went into 1.59, and has been picked up by the distributions. Can we now try moving away from rust nightlies and see if it can be made to work?

@dubek
Copy link
Contributor

dubek commented Dec 20, 2022

A quick build shows that the use of xargo can be replaced with cargo (but it still uses unstable features defined in .cargo/config.toml):

diff --git a/Makefile b/Makefile
index 5f4a012..af0bbf8 100644
--- a/Makefile
+++ b/Makefile
@@ -46,7 +46,7 @@ svsm.bin.elf: $(OBJS) src/start/svsm.lds
        $(GCC) $(LD_FLAGS) -o $@ $(OBJS)

 %.a: src/*.rs src/cpu/*.rs src/mem/*.rs src/util/*.rs
-       @xargo build --features $(FEATURES)
+       cargo build --features $(FEATURES)

 %.o: %.S src/start/svsm.h
        $(GCC) $(C_FLAGS) $(LDS_FLAGS) $(A_FLAGS) -c -o $@ $<
@@ -64,12 +64,11 @@ prereq: .prereq
        rustup component add rust-src
        rustup component add llvm-tools-preview
        rustup override set nightly
-       cargo install xargo
        cargo install bootimage
        touch .prereq

 clean:
-       @xargo clean
+       cargo clean
        rm -f svsm.bin svsm.bin.elf $(OBJS)
        rm -rf $(TARGET_DIR)
        rm -f src/start/svsm.lds

I haven't yet tried booting with it, but it compiled nicely.

@jejb
Copy link
Author

jejb commented Dec 20, 2022

This doesn't quite work for me; I get

error: language item required, but not found: eh_personality
|
= note: this can occur when a binary crate with #![no_std] is compiled for a target where eh_personality is defined in the standard library
= help: you may be able to compile for a target that doesn't need eh_personality, specify a target with --target or in .cargo/config

To fix this, I have to specify a --target x86_64-unknown-none to cargo:

diff --git a/Makefile b/Makefile
index 5f4a012..e624dc2 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,7 @@ LD_FLAGS	+= -nostdlib
 LD_FLAGS	+= -Wl,-Tsrc/start/svsm.lds -Wl,--build-id=none
 
 TARGET_DIR	:= target
-TARGET		:= $(TARGET_DIR)/svsm-target/debug
+TARGET		:= $(TARGET_DIR)/x86_64-unknown-none/debug
 
 OBJS		:= src/start/start.o
 OBJS		+= $(TARGET)/liblinux_svsm.a
@@ -46,7 +46,7 @@ svsm.bin.elf: $(OBJS) src/start/svsm.lds
 	$(GCC) $(LD_FLAGS) -o $@ $(OBJS)
 
 %.a: src/*.rs src/cpu/*.rs src/mem/*.rs src/util/*.rs
-	@xargo build --features $(FEATURES)
+	cargo build --features $(FEATURES) --target x86_64-unknown-none
 
 %.o: %.S src/start/svsm.h
 	$(GCC) $(C_FLAGS) $(LDS_FLAGS) $(A_FLAGS) -c -o $@ $<

@dubek
Copy link
Contributor

dubek commented Dec 20, 2022

hmmm, cargo should have read its settings from .cargo/config.toml, which states target = "svsm-target.json" which is the equivalent of cargo build --target svsm-target.json . Can you try that?
(but I'm not sure why it's not picking it up by itself for you)

@jejb
Copy link
Author

jejb commented Dec 20, 2022

Oh, right, that would be my fault then, I removed .cargo trying to clean my downloaded build environment. Doing a git reset put it back and now the patch works as expected. Sorry about the noise.

@arkivm
Copy link
Contributor

arkivm commented Dec 22, 2022

Blocked by

@Zildj1an
Copy link
Contributor

Zildj1an commented Jan 3, 2023

I'm completely in favor of switching to standard Rust. Besides the reasons already mentioned, we are missing out on crates that don't offer an #![no_std] alternative. Let's leave this issue open and keep an eye on the tracked issues mentioned by @arkivm.

@Zildj1an
Copy link
Contributor

Zildj1an commented Jan 23, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants