-
-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cross compilation improvements #5781
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,7 @@ use tempfile::NamedTempFile; | |
const HOST_WASM: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/builtins-wasm32.o")); | ||
// TODO: in the future, we should use Zig's cross-compilation to generate and store these | ||
// for all targets, so that we can do cross-compilation! | ||
#[cfg(unix)] | ||
const HOST_UNIX: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/builtins-host.o")); | ||
#[cfg(windows)] | ||
const HOST_WINDOWS: &[u8] = | ||
include_bytes!(concat!(env!("OUT_DIR"), "/builtins-windows-x86_64.obj")); | ||
|
||
|
@@ -21,45 +19,71 @@ pub fn host_wasm_tempfile() -> std::io::Result<NamedTempFile> { | |
Ok(tempfile) | ||
} | ||
|
||
#[cfg(unix)] | ||
fn host_unix_tempfile() -> std::io::Result<NamedTempFile> { | ||
let tempfile = tempfile::Builder::new() | ||
.prefix("host_bitcode") | ||
.suffix(".o") | ||
.rand_bytes(8) | ||
.tempfile()?; | ||
fn current_host_tempfile() -> &'static std::io::Result<NamedTempFile> { | ||
use std::sync::OnceLock; | ||
|
||
std::fs::write(tempfile.path(), HOST_UNIX)?; | ||
static TMP: OnceLock<std::io::Result<NamedTempFile>> = OnceLock::new(); | ||
|
||
Ok(tempfile) | ||
} | ||
fn helper() -> std::io::Result<NamedTempFile> { | ||
let tempfile = tempfile::Builder::new() | ||
.prefix("host_bitcode") | ||
.suffix(".o") | ||
.rand_bytes(8) | ||
.tempfile()?; | ||
|
||
#[cfg(windows)] | ||
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_UNIX)?; | ||
|
||
std::fs::write(tempfile.path(), HOST_WINDOWS)?; | ||
Ok(tempfile) | ||
} | ||
|
||
Ok(tempfile) | ||
TMP.get_or_init(helper) | ||
} | ||
|
||
pub fn host_tempfile() -> std::io::Result<NamedTempFile> { | ||
#[cfg(unix)] | ||
{ | ||
host_unix_tempfile() | ||
} | ||
fn host_windows_tempfile() -> &'static std::io::Result<NamedTempFile> { | ||
use std::sync::OnceLock; | ||
|
||
static TMP: OnceLock<std::io::Result<NamedTempFile>> = OnceLock::new(); | ||
|
||
#[cfg(windows)] | ||
{ | ||
host_windows_tempfile() | ||
fn helper() -> 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) | ||
} | ||
|
||
#[cfg(not(any(windows, unix)))] | ||
{ | ||
unreachable!() | ||
TMP.get_or_init(helper) | ||
} | ||
|
||
pub fn host_tempfile(target: &target_lexicon::Triple) -> &'static std::io::Result<NamedTempFile> { | ||
use target_lexicon::Triple; | ||
|
||
match target { | ||
Triple { | ||
// architecture: target_lexicon::Architecture::X86_64, | ||
// operating_system: target_lexicon::OperatingSystem::Linux, | ||
Comment on lines
+67
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in practice the "unix" host file is the file compiled for this host. That means that we need to be pretty vague in this pattern to not cause regressions. Eventually we should generate the builtins for more targets, and be more specific here. |
||
binary_format: target_lexicon::BinaryFormat::Elf, | ||
.. | ||
} => current_host_tempfile(), | ||
|
||
// macho support is incomplete | ||
Triple { | ||
// operating_system: target_lexicon::OperatingSystem::Darwin, | ||
binary_format: target_lexicon::BinaryFormat::Macho, | ||
.. | ||
} => current_host_tempfile(), | ||
|
||
Triple { | ||
architecture: target_lexicon::Architecture::X86_64, | ||
operating_system: target_lexicon::OperatingSystem::Windows, | ||
binary_format: target_lexicon::BinaryFormat::Coff, | ||
.. | ||
} => host_windows_tempfile(), | ||
|
||
other => unimplemented!("no host for {other:?} architecture"), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,33 +32,35 @@ pub enum LinkType { | |
} | ||
|
||
pub fn supported(link_type: LinkType, target: &Triple) -> bool { | ||
if let LinkType::Executable = link_type { | ||
match target { | ||
Triple { | ||
architecture: target_lexicon::Architecture::X86_64, | ||
operating_system: target_lexicon::OperatingSystem::Linux, | ||
binary_format: target_lexicon::BinaryFormat::Elf, | ||
.. | ||
} => true, | ||
|
||
// macho support is incomplete | ||
Triple { | ||
operating_system: target_lexicon::OperatingSystem::Darwin, | ||
binary_format: target_lexicon::BinaryFormat::Macho, | ||
.. | ||
} => false, | ||
|
||
Triple { | ||
architecture: target_lexicon::Architecture::X86_64, | ||
operating_system: target_lexicon::OperatingSystem::Windows, | ||
binary_format: target_lexicon::BinaryFormat::Coff, | ||
.. | ||
} => true, | ||
|
||
_ => false, | ||
match link_type { | ||
LinkType::Executable => { | ||
match target { | ||
Triple { | ||
architecture: target_lexicon::Architecture::X86_64, | ||
operating_system: target_lexicon::OperatingSystem::Linux, | ||
binary_format: target_lexicon::BinaryFormat::Elf, | ||
.. | ||
} => true, | ||
|
||
// macho support is incomplete | ||
Triple { | ||
operating_system: target_lexicon::OperatingSystem::Darwin, | ||
binary_format: target_lexicon::BinaryFormat::Macho, | ||
.. | ||
} => false, | ||
|
||
Triple { | ||
architecture: target_lexicon::Architecture::X86_64, | ||
operating_system: target_lexicon::OperatingSystem::Windows, | ||
binary_format: target_lexicon::BinaryFormat::Coff, | ||
.. | ||
} => true, | ||
|
||
_ => false, | ||
} | ||
} | ||
} else { | ||
false | ||
LinkType::Dylib => false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. linking the dev tests (using zig, today) into a dylib is slow. I think (and fear) that we need to go do this ourselves. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it's not so bad? it's just a fancy copy https://github.com/gimli-rs/object/blob/master/crates/examples/src/bin/pecopy.rs fancy because we need to join two files, the test code and the builtins. |
||
LinkType::None => false, | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should mean that the file is only created once per test run