Skip to content

Commit

Permalink
include rustc version, use DLL_SUFFIX
Browse files Browse the repository at this point in the history
  • Loading branch information
enricozb committed Apr 29, 2024
1 parent e9ada34 commit c582dd5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
8 changes: 8 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::{env, process::Command};

fn main() {
let rustc_version = Command::new(env::var("RUSTC").unwrap()).arg("--version").output().unwrap().stdout;

Check warning on line 4 in build.rs

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (rustc)

Check warning on line 4 in build.rs

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (RUSTC)
let rustc_version = String::from_utf8(rustc_version).unwrap();

Check warning on line 5 in build.rs

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (rustc)

Check warning on line 5 in build.rs

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (rustc)

println!("cargo::rustc-env=RUSTC_VERSION={rustc_version}");

Check warning on line 7 in build.rs

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (rustc)

Check warning on line 7 in build.rs

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (RUSTC)

Check warning on line 7 in build.rs

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (rustc)
}
34 changes: 25 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use hvmc::{

use parking_lot::Mutex;
use std::{
env::consts::{DLL_EXTENSION, DLL_PREFIX},
env::consts::{DLL_PREFIX, DLL_SUFFIX},
ffi::OsStr,
fmt::Write,
fs::{self, File},
Expand Down Expand Up @@ -50,7 +50,7 @@ fn main() {
prepare_temp_hvm_dylib().unwrap();
compile_temp_hvm(&["--lib"]).unwrap();

fs::copy(format!(".hvm/target/release/{DLL_PREFIX}hvmc.{DLL_EXTENSION}"), output).unwrap();
fs::copy(format!(".hvm/target/release/{DLL_PREFIX}hvmc{DLL_SUFFIX}"), output).unwrap();
} else {
compile_temp_hvm(&[]).unwrap();

Expand Down Expand Up @@ -281,11 +281,22 @@ fn load_dylibs(host: Arc<Mutex<Host>>, include: &[PathBuf]) {
}
.expect("failed to load dylib");

let dylib_version = lib.get::<fn() -> &'static str>(b"hvmc_dylib_v0__version").expect("failed to load version");
let dylib_version = dylib_version();
if dylib_version != env!("CARGO_PKG_VERSION") {
let rust_version =
lib.get::<fn() -> &'static str>(b"hvmc_dylib_v0__rust_version").expect("failed to load rust version");
let rust_version = rust_version();
if rust_version != env!("RUSTC_VERSION") {

Check warning on line 287 in src/main.rs

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (RUSTC)
eprintln!(
"warning: dylib {file:?} was compiled with hvmc version {dylib_version}, but is being run with hvmc version {}",
"warning: dylib {file:?} was compiled with rust version {rust_version}, but is being run with rust version {}",
env!("RUSTC_VERSION")

Check warning on line 290 in src/main.rs

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (RUSTC)
);
}

let hvmc_version =
lib.get::<fn() -> &'static str>(b"hvmc_dylib_v0__hvmc_version").expect("failed to load hvmc version");
let hvmc_version = hvmc_version();
if hvmc_version != env!("CARGO_PKG_VERSION") {
eprintln!(
"warning: dylib {file:?} was compiled with hvmc version {hvmc_version}, but is being run with hvmc version {}",
env!("CARGO_PKG_VERSION")
);
}
Expand Down Expand Up @@ -446,12 +457,17 @@ pub fn hvmc_dylib_v0__insert_host(host: &mut host::Host) {{
}}
#[no_mangle]
pub fn hvmc_dylib_v0__version() -> &'static str {{
{:?}
pub fn hvmc_dylib_v0__hvmc_version() -> &'static str {{
{hvmc_version:?}
}}
#[no_mangle]
pub fn hvmc_dylib_v0__rust_version() -> &'static str {{
{rust_version:?}
}}
"#,
env!("CARGO_PKG_VERSION")
hvmc_version = env!("CARGO_PKG_VERSION"),
rust_version = env!("RUSTC_VERSION"),

Check warning on line 470 in src/main.rs

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (RUSTC)
)
.unwrap();

Expand Down

0 comments on commit c582dd5

Please sign in to comment.