Centralize host tempfile builder logic

This commit is contained in:
Richard Feldman 2022-11-22 20:38:59 -05:00
parent 4b64f8c9e9
commit 69a7c3ea15
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
7 changed files with 95 additions and 117 deletions

View file

@ -1,6 +1,7 @@
use roc_module::symbol::Symbol;
use roc_target::TargetInfo;
use std::ops::Index;
use tempfile::NamedTempFile;
pub const HOST_WASM: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/bitcode/builtins-wasm32.o"));
// TODO: in the future, we should use Zig's cross-compilation to generate and store these
@ -13,6 +14,44 @@ pub const HOST_WINDOWS: &[u8] = include_bytes!(concat!(
"/bitcode/builtins-windows-x86_64.obj"
));
pub fn host_wasm_tempfile() -> std::io::Result<NamedTempFile> {
let tempfile = tempfile::Builder::new()
.prefix("host_bitcode")
.suffix(".wasm")
.rand_bytes(8)
.tempfile()?;
std::fs::write(tempfile.path(), HOST_WASM)?;
Ok(tempfile)
}
#[cfg(unix)]
pub fn host_unix_tempfile() -> std::io::Result<NamedTempFile> {
let tempfile = tempfile::Builder::new()
.prefix("host_bitcode")
.suffix(".o")
.rand_bytes(8)
.tempfile()?;
std::fs::write(tempfile.path(), HOST_UNIX)?;
Ok(tempfile)
}
#[cfg(windows)]
pub fn host_windows_tempfile() -> std::io::Result<NamedTempFile> {
let tempfile = tempfile::Builder::new()
.prefix("host_bitcode")
.suffix(".obj")
.rand_bytes(8)
.tempfile()?;
std::fs::write(tempfile.path(), HOST_WINDOWS)?;
Ok(tempfile)
}
#[derive(Debug, Default, Copy, Clone)]
pub struct IntrinsicName {
pub options: [&'static str; 14],