add test for preprocessing on a zig host

This commit is contained in:
Folkert 2022-09-18 00:58:27 +02:00
parent daa7e72a2f
commit 61366f0d43
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

@ -621,4 +621,77 @@ mod test {
assert_eq!(new_sections, names.as_slice());
}
#[test]
fn preprocess_zig_host() {
let host_zig = include_str!("../trivial_host.zig");
let app_zig = include_str!("../trivial_app.zig");
let zig = std::env::var("ROC_ZIG").unwrap_or_else(|_| "zig".into());
let dir = tempfile::tempdir().unwrap();
let dir = dir.path();
std::fs::write(dir.join("trivial_host.zig"), host_zig.as_bytes()).unwrap();
std::fs::write(dir.join("trivial_app.zig"), app_zig.as_bytes()).unwrap();
// here we would like to do
//
// let dylib_bytes = crate::generate_dylib::synthetic_dll(&["double".into(), "triple".into()]);
// std::fs::write(dir.join("roc-cheaty-lib.dll"), dylib_bytes).unwrap();
//
// but on windows, this is not so simple. To link a .dll into an .exe we need an additional
// .lib file, a so-called "import library". These are normally generated by the linker, and
// based on some googling there is other tooling on windows that can also generate them
// from a .dll. There is however very little information on what they should contain.
//
// Jakub intends to implement generating the .lib files in pure zig in the near(ish)
// future, so if we can wait then we can use the zig source to create our own logic for
// a very simple .lib file
let output = std::process::Command::new(&zig)
.current_dir(dir)
.args(&[
"build-lib",
"trivial_app.zig",
"-target",
"x86_64-windows-gnu",
"--strip",
"-OReleaseFast",
])
.output()
.unwrap();
if !output.status.success() {
use std::io::Write;
std::io::stdout().write_all(&output.stdout).unwrap();
std::io::stderr().write_all(&output.stderr).unwrap();
panic!();
}
let output = std::process::Command::new(&zig)
.current_dir(dir)
.args(&[
"build-exe",
"trivial_host.zig",
"trivial_app.lib",
"-target",
"x86_64-windows-gnu",
"--strip",
"-OReleaseFast",
])
.output()
.unwrap();
if !output.status.success() {
use std::io::Write;
std::io::stdout().write_all(&output.stdout).unwrap();
std::io::stderr().write_all(&output.stderr).unwrap();
panic!();
}
}
}