Skip to content

Commit

Permalink
fix: make shims cargo test --workspace compatible
Browse files Browse the repository at this point in the history
Signed-off-by: Harald Hoyer <harald@profian.com>
  • Loading branch information
haraldh committed Dec 21, 2022
1 parent 84c3360 commit f057c43
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
17 changes: 11 additions & 6 deletions crates/shim-kvm/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// SPDX-License-Identifier: Apache-2.0

use std::env::var;

fn main() {
println!(
"cargo:rustc-link-arg-bin=enarx-shim-kvm=-T{}/layout.ld",
std::env::var("CARGO_MANIFEST_DIR").unwrap()
);
println!("cargo:rustc-link-arg-bin=enarx-shim-kvm=-Wl,--sort-section=alignment");
println!("cargo:rustc-link-arg-bin=enarx-shim-kvm=-nostartfiles");
let target_os = var("CARGO_CFG_TARGET_OS").expect("missing CARGO_CFG_TARGET_OS");
if target_os == "none" {
println!(
"cargo:rustc-link-arg-bin=enarx-shim-kvm=-T{}/layout.ld",
std::env::var("CARGO_MANIFEST_DIR").unwrap()
);
println!("cargo:rustc-link-arg-bin=enarx-shim-kvm=-Wl,--sort-section=alignment");
println!("cargo:rustc-link-arg-bin=enarx-shim-kvm=-nostartfiles");
}
}
8 changes: 7 additions & 1 deletion crates/shim-kvm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#![deny(clippy::all)]
#![deny(missing_docs)]
#![warn(rust_2018_idioms)]
#![no_main]
#![cfg_attr(target_os = "none", no_main)]
#![feature(asm_const)]
#![cfg_attr(coverage, feature(no_coverage))]

Expand Down Expand Up @@ -102,6 +102,7 @@ unsafe fn switch_shim_stack(ip: extern "sysv64" fn() -> !, sp: u64) -> ! {
///
/// # Safety
/// Do not call from Rust.
#[cfg(target_os = "none")]
#[cfg_attr(coverage, no_coverage)]
unsafe extern "sysv64" fn _pre_main(c_bit_mask: u64) -> ! {
C_BIT_MASK.store(c_bit_mask, Ordering::Relaxed);
Expand All @@ -115,7 +116,11 @@ unsafe extern "sysv64" fn _pre_main(c_bit_mask: u64) -> ! {
switch_shim_stack(main, gdt::INITIAL_STACK.pointer.as_u64())
}

#[cfg(not(target_os = "none"))]
pub fn main() {}

/// The main function for the shim with stack setup
#[cfg(target_os = "none")]
#[cfg_attr(coverage, no_coverage)]
extern "sysv64" fn main() -> ! {
unsafe { gdt::init() };
Expand Down Expand Up @@ -194,6 +199,7 @@ macro_rules! correct_table_c_bit {
};
}

#[cfg(target_os = "none")]
// The initial function called at startup
//
// It sets up essential registers, page tables and jumps in shim virtual address space
Expand Down
18 changes: 12 additions & 6 deletions crates/shim-sgx/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
// SPDX-License-Identifier: Apache-2.0

use std::env::var;

fn main() {
println!(
"cargo:rustc-link-arg-bin=enarx-shim-sgx=-T{}/layout.ld",
std::env::var("CARGO_MANIFEST_DIR").unwrap()
);
println!("cargo:rustc-link-arg-bin=enarx-shim-sgx=-Wl,--sort-section=alignment");
println!("cargo:rustc-link-arg-bin=enarx-shim-sgx=-nostartfiles");
let target_os = var("CARGO_CFG_TARGET_OS").expect("missing CARGO_CFG_TARGET_OS");

if target_os == "none" {
println!(
"cargo:rustc-link-arg-bin=enarx-shim-sgx=-T{}/layout.ld",
std::env::var("CARGO_MANIFEST_DIR").unwrap()
);
println!("cargo:rustc-link-arg-bin=enarx-shim-sgx=-Wl,--sort-section=alignment");
println!("cargo:rustc-link-arg-bin=enarx-shim-sgx=-nostartfiles");
}
}
8 changes: 7 additions & 1 deletion crates/shim-sgx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#![deny(clippy::all)]
#![deny(missing_docs)]
#![warn(rust_2018_idioms)]
#![no_main]
#![cfg_attr(target_os = "none", no_main)]

#[allow(unused_extern_crates)]
extern crate rcrt1;
Expand Down Expand Up @@ -193,6 +193,8 @@ extern "sysv64" {
/// Do not call this function from Rust. It is the entry point for SGX.
pub fn _start();
}

#[cfg(target_os = "none")]
global_asm!(
".pushsection .text.startup,\"ax\",@progbits",
".global _start",
Expand Down Expand Up @@ -295,6 +297,10 @@ fn validate_block_ptr(ptr: *mut u8) -> &'static mut [usize; BLOCK_SIZE / size_of
unsafe { &mut *(ptr as *mut [usize; BLOCK_SIZE / size_of::<usize>()]) }
}

#[cfg(not(target_os = "none"))]
pub fn main() {}

#[cfg(target_os = "none")]
unsafe extern "C" fn main(
block_ptr: *mut u8,
ssas: &mut [StateSaveArea; NUM_SSA],
Expand Down

0 comments on commit f057c43

Please sign in to comment.