mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Centralize host tempfile builder logic
This commit is contained in:
parent
4b64f8c9e9
commit
69a7c3ea15
7 changed files with 95 additions and 117 deletions
|
@ -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],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue