Merge pull request #4565 from roc-lang/more-standalone

Use include_bytes! so builtin hosts live in binary
This commit is contained in:
Folkert de Vries 2022-11-23 13:01:39 +01:00 committed by GitHub
commit 099ab4938f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 146 additions and 72 deletions

View file

@ -17,7 +17,6 @@ use roc_target::TargetInfo;
use std::time::{Duration, Instant};
use std::{path::PathBuf, thread::JoinHandle};
use target_lexicon::Triple;
use tempfile::Builder;
fn report_timing(buf: &mut String, label: &str, duration: Duration) {
use std::fmt::Write;
@ -331,7 +330,7 @@ pub fn build_file<'a>(
problems
}
(LinkingStrategy::Legacy, _) => {
let app_o_file = Builder::new()
let app_o_file = tempfile::Builder::new()
.prefix("roc_app")
.suffix(&format!(".{}", app_extension))
.tempfile()
@ -345,20 +344,35 @@ pub fn build_file<'a>(
app_o_file.to_str().unwrap(),
];
let str_host_obj_path = bitcode::get_builtins_host_obj_path();
let builtins_host_tempfile = {
#[cfg(unix)]
{
bitcode::host_unix_tempfile()
}
#[cfg(windows)]
{
bitcode::host_windows_tempfile()
}
}
.expect("failed to write host builtins object to tempfile");
if matches!(code_gen_options.backend, program::CodeGenBackend::Assembly) {
inputs.push(&str_host_obj_path);
inputs.push(builtins_host_tempfile.path().to_str().unwrap());
}
let (mut child, _) = // TODO use lld
link(target, binary_path.clone(), &inputs, link_type)
.map_err(|_| todo!("gracefully handle `ld` failing to spawn."))?;
link(target, binary_path.clone(), &inputs, link_type)
.map_err(|_| todo!("gracefully handle `ld` failing to spawn."))?;
let exit_status = child
.wait()
.map_err(|_| todo!("gracefully handle error after `ld` spawned"))?;
// Extend the lifetime of the tempfile so it doesn't get dropped
// (and thus deleted) before the child process is done using it!
let _ = builtins_host_tempfile;
if exit_status.success() {
problems
} else {