Skip to content

Commit

Permalink
Improved Native support
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Nov 20, 2020
1 parent debd76b commit 47c958d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
6 changes: 5 additions & 1 deletion examples/engine_cross_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

#[test]
#[cfg(not(windows))]
#[cfg(not(any(
windows,
// We don't support yet crosscompilation in macOS with Apple Silicon
all(target_os = "macos", target_arch = "aarch64")
)))]
fn test_cross_compilation() -> Result<(), Box<dyn std::error::Error>> {
main()
}
17 changes: 14 additions & 3 deletions lib/engine-native/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,26 @@ impl NativeArtifact {
};

let is_cross_compiling = engine_inner.is_cross_compiling();
let target_triple_str = {
let into_str = target_triple.to_string();
// We have to adapt the target triple string, because otherwise
// Apple's clang will not recognize it.
if into_str == "aarch64-apple-darwin" {
"arm64-apple-darwin".to_string()
} else {
into_str
}
};

let cross_compiling_args: Vec<String> = if is_cross_compiling {
vec![
format!("--target={}", target_triple),
format!("--target={}", target_triple_str),
"-fuse-ld=lld".to_string(),
"-nodefaultlibs".to_string(),
"-nostdlib".to_string(),
]
} else {
vec![]
vec![format!("--target={}", target_triple_str)]
};
let target_args = match (target_triple.operating_system, is_cross_compiling) {
(OperatingSystem::Windows, true) => vec!["-Wl,/force:unresolved,/noentry"],
Expand All @@ -271,7 +282,7 @@ impl NativeArtifact {
};
trace!(
"Compiling for target {} from host {}",
target_triple.to_string(),
target_triple_str,
Triple::host().to_string(),
);

Expand Down
6 changes: 6 additions & 0 deletions lib/object/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ pub fn emit_compilation(
RelocationKind::PltRelative,
RelocationEncoding::X86Branch,
),
// Object doesn't fully support it yet
// Architecture::Aarch64(_) => (
// 32,
// RelocationKind::PltRelative,
// RelocationEncoding::Generic,
// ),
architecture => {
return Err(ObjectError::UnsupportedArchitecture(
architecture.to_string(),
Expand Down
3 changes: 2 additions & 1 deletion tests/compilers/traps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ fn mismatched_arguments() -> Result<()> {
any(
feature = "test-singlepass",
feature = "test-llvm",
feature = "test-native"
feature = "test-native",
all(target_os = "macos", target_arch = "aarch64")
),
ignore
)]
Expand Down

0 comments on commit 47c958d

Please sign in to comment.