徐启航 il y a 2 ans
Parent
commit
d23795e28d

+ 3 - 0
Cargo.toml

@@ -11,3 +11,6 @@ members = [
 ]
 
 exclude = ["src/bin/.cargo"]
+
+[patch.crates-io]
+libc = {path = "../toolchains/rust-libc"}

+ 1 - 5
src/bin/.cargo/config.toml

@@ -1,9 +1,5 @@
 [build]
-target = "../../.cargo/x86_64-pc-oceanic.json"
-
-[unstable]
-build-std = ["core", "compiler_builtins", "alloc", "panic_abort"]
-build-std-features = ["compiler-builtins-mem"]
+target = "x86_64-pc-oceanic"
 
 [profile.dev]
 incremental = true

+ 32 - 40
src/bin/progm/src/main.rs

@@ -1,54 +1,46 @@
-#![no_std]
-#![no_main]
 #![feature(alloc_error_handler)]
 
-use solvent::prelude::Handle;
+// #[no_mangle]
+// unsafe extern "C" fn _start(init_chan: Handle) {
+//     __libc_start_main(init_chan, main)
+// }
 
-#[no_mangle]
-unsafe extern "C" fn _start(init_chan: Handle) {
-    __libc_start_main(init_chan, main)
-}
+fn main() {}
 
-#[no_mangle]
-unsafe extern "C" fn main(_: u32, _: *mut *mut i8, _: *mut *mut i8) -> i32 {
-    0
-}
-
-type Main = unsafe extern "C" fn(argc: u32, argv: *mut *mut i8, environ: *mut *mut i8) -> i32;
+// type Main = unsafe extern "C" fn(argc: u32, argv: *mut *mut i8, environ: *mut
+// *mut i8) -> i32;
 
 #[link(name = "co2")]
-extern "C" {
-    fn __libc_start_main(init_chan: Handle, main: Main) -> !;
-}
+extern "C" {}
 
-#[panic_handler]
-fn rust_begin_unwind(info: &core::panic::PanicInfo) -> ! {
-    log::error!("{}", info);
+// #[panic_handler]
+// fn rust_begin_unwind(info: &core::panic::PanicInfo) -> ! {
+//     log::error!("{}", info);
 
-    loop {
-        unsafe { core::arch::asm!("pause; ud2") }
-    }
-}
+//     loop {
+//         unsafe { core::arch::asm!("pause; ud2") }
+//     }
+// }
 
-/// The function indicating memory runs out.
-#[alloc_error_handler]
-fn rust_oom(layout: core::alloc::Layout) -> ! {
-    log::error!("Allocation error for {:?}", layout);
+// /// The function indicating memory runs out.
+// #[alloc_error_handler]
+// fn rust_oom(layout: core::alloc::Layout) -> ! {
+//     log::error!("Allocation error for {:?}", layout);
 
-    loop {
-        unsafe { core::arch::asm!("pause; ud2") }
-    }
-}
+//     loop {
+//         unsafe { core::arch::asm!("pause; ud2") }
+//     }
+// }
 
-struct NullAlloc;
+// struct NullAlloc;
 
-#[global_allocator]
-static NULL_ALLOC: NullAlloc = NullAlloc;
+// #[global_allocator]
+// static NULL_ALLOC: NullAlloc = NullAlloc;
 
-unsafe impl core::alloc::GlobalAlloc for NullAlloc {
-    unsafe fn alloc(&self, _: core::alloc::Layout) -> *mut u8 {
-        core::ptr::null_mut()
-    }
+// unsafe impl core::alloc::GlobalAlloc for NullAlloc {
+//     unsafe fn alloc(&self, _: core::alloc::Layout) -> *mut u8 {
+//         core::ptr::null_mut()
+//     }
 
-    unsafe fn dealloc(&self, _: *mut u8, _: core::alloc::Layout) {}
-}
+//     unsafe fn dealloc(&self, _: *mut u8, _: core::alloc::Layout) {}
+// }

+ 1 - 5
src/lib/libc/.cargo/config.toml

@@ -1,9 +1,5 @@
 [build]
-target = "../../../.cargo/x86_64-pc-oceanic.json"
-
-[unstable]
-build-std = ["core", "compiler_builtins", "alloc", "panic_abort"]
-build-std-features = ["compiler-builtins-mem"]
+target = "x86_64-pc-oceanic"
 
 [profile.dev]
 incremental = true

+ 1 - 0
src/lib/libc/ldso/Cargo.toml

@@ -15,6 +15,7 @@ rpc = {path = "../../rpc"}
 solvent = {path = "../../h2o_rs"}
 svrt = {path = "../../svrt"}
 # External crates
+compiler_builtins = {version = "0.1", features = ["mem"]}
 cstr_core = "0.2"
 goblin = {version = "0.5", default-features = false, features = ["elf32", "elf64", "endian_fd"]}
 log = "0.4"

+ 2 - 1
xtask/src/check.rs

@@ -9,7 +9,7 @@ use std::{
 use crate::{H2O_BOOT, H2O_KERNEL, H2O_TINIT, OC_BIN, OC_LIB};
 
 pub(crate) fn check() -> Result<(), Box<dyn Error>> {
-    let cargo = env::var("CARGO").unwrap_or_else(|_| "cargo".to_string());
+    let cargo = "cargo".to_string();
     let src_root = Path::new(env!("CARGO_MANIFEST_DIR"))
         .ancestors()
         .nth(1)
@@ -18,6 +18,7 @@ pub(crate) fn check() -> Result<(), Box<dyn Error>> {
     let check = |dir: PathBuf| -> Result<(), Box<dyn Error>> {
         Command::new(&cargo)
             .current_dir(dir)
+            .arg("+oceanic")
             .args(["clippy", "--message-format=json-diagnostic-short"])
             .status()?
             .exit_ok()

+ 5 - 8
xtask/src/dist.rs

@@ -35,7 +35,7 @@ impl Dist {
     }
 
     pub fn build(self) -> Result<(), Box<dyn Error>> {
-        let cargo = env::var("CARGO").unwrap_or_else(|_| "cargo".to_string());
+        let cargo = "cargo".to_string();
         let src_root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
         let target_root = env::var("CARGO_TARGET_DIR")
             .unwrap_or_else(|_| src_root.join("target").to_string_lossy().to_string());
@@ -65,19 +65,16 @@ impl Dist {
 
         // Build the VDSO
         {
-            let target_triple = src_root.join(".cargo/x86_64-pc-oceanic.json");
             let cd = src_root.join(H2O_SYSCALL);
             let ldscript = cd.join("syscall.ld");
 
             println!("Building VDSO");
 
             let mut cmd = Command::new(&cargo);
-            let cmd = cmd.current_dir(&cd).arg("rustc").args([
-                "--crate-type=cdylib",
-                &format!("--target={}", target_triple.to_string_lossy()),
+            let cmd = cmd.current_dir(&cd).arg("+oceanic").arg("rustc").args([
                 "-Zunstable-options",
-                "-Zbuild-std=core,compiler_builtins,alloc,panic_abort",
-                "-Zbuild-std-features=compiler-builtins-mem",
+                "--crate-type=cdylib",
+                "--target=x86_64-pc-oceanic",
                 "--release", /* VDSO can always be the release version and discard the debug
                               * symbols. */
                 "--no-default-features",
@@ -262,7 +259,7 @@ impl Dist {
         println!("Building {:?}", dst_name.as_ref());
 
         let mut cmd = Command::new(cargo);
-        let cmd = cmd.current_dir(src_dir).arg("build");
+        let cmd = cmd.current_dir(src_dir).arg("+oceanic").arg("build");
         if self.release {
             cmd.arg("--release");
         }