Skip to content

Commit 8274985

Browse files
authored
Add a hyperlight cfg for conditional compilation (#2)
* add a hyperlight cfg for conditional compilation Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> * test hyperlight cfg in guest example Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> --------- Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
1 parent 242376b commit 8274985

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

examples/guest/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
extern crate alloc;
55

6+
const _: () = {
7+
#[cfg(not(hyperlight))]
8+
compile_error!("This crate can only be compiled for hyperlight targets");
9+
};
10+
611
use alloc::format;
712
use alloc::vec::Vec;
813

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ impl CargoCommandExt for std::process::Command {
8383
fn populate_from_args(&mut self, args: &Args) -> &mut Self {
8484
self.target(&args.target);
8585
self.sysroot(args.sysroot_dir());
86+
self.append_rustflags("--cfg=hyperlight");
87+
self.append_rustflags("--check-cfg=cfg(hyperlight)");
8688
self.entrypoint("entrypoint");
8789
if let Some(clang) = &args.clang {
8890
self.cc_env(&args.target, clang);

src/toolchain.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub fn prepare(args: &Args) -> Result<()> {
2929
.arg("metadata")
3030
.manifest_path(&args.manifest_path)
3131
.arg("--format-version=1")
32+
.append_rustflags("--cfg=hyperlight")
33+
.append_rustflags("--check-cfg=cfg(hyperlight)")
3234
.checked_output()
3335
.context("Failed to get cargo metadata")?;
3436

0 commit comments

Comments
 (0)