Skip to content

Commit

Permalink
feat: add Mac M1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed Aug 27, 2022
1 parent fb6d7b1 commit 8aaf3f2
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Mac M1 Support [#](https://github.com/mun-lang/mun/pull/444)

## [0.3.0] - 2021-04-12

The third Mun release includes big usability improvements; multi-file projects, a language server with diagnostics and autocompletion, and improvements to robustness and developer workflow to name a few.
Expand Down
2 changes: 1 addition & 1 deletion crates/mun/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ default-run = "mun"
anyhow = "1.0.31"
clap = { version = "3.1.18", features=["derive"] }
log = "0.4"
pretty_env_logger = "0.4"
mun_abi = { version = "=0.3.0", path = "../mun_abi" }
mun_compiler = { version = "=0.3.0", path = "../mun_compiler" }
mun_compiler_daemon = { version = "=0.3.0", path = "../mun_compiler_daemon" }
mun_runtime = { version = "=0.3.0", path = "../mun_runtime" }
mun_language_server = { version = "=0.1.0", path = "../mun_language_server" }
mun_project = { version = "=0.1.0", path = "../mun_project" }
pretty_env_logger = "0.4"

[dev-dependencies.cargo-husky]
version = "1"
Expand Down
1 change: 1 addition & 0 deletions crates/mun_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ categories = ["Game development", "Mun"]
[dependencies]
rustc-hash = "1.1.0"
abi = { version = "=0.3.0", path = "../mun_abi", package = "mun_abi" }
apple-codesign = "0.17.0"
bytemuck = "1.4.1"
hir = { version = "=0.3.0", path = "../mun_hir", package = "mun_hir" }
itertools = "0.10.3"
Expand Down
9 changes: 9 additions & 0 deletions crates/mun_codegen/src/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
ModuleGroupId,
};
use anyhow::anyhow;
use apple_codesign::{SigningSettings, UnifiedSigner};
use inkwell::context::Context;
use std::{path::Path, sync::Arc};
use tempfile::NamedTempFile;
Expand Down Expand Up @@ -106,6 +107,14 @@ pub(crate) fn build_target_assembly(
.into_shared_object(file.path())
.expect("could not link object file");

let target = db.target();
if target.options.is_like_osx {
let signer = UnifiedSigner::new(SigningSettings::default());
signer
.sign_path_in_place(file.path())
.expect("Failed to sign shared object");
}

Arc::new(TargetAssembly { file })
}

Expand Down
39 changes: 25 additions & 14 deletions crates/mun_runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod reflection;
use anyhow::Result;
use dispatch_table::DispatchTable;
use garbage_collector::GarbageCollector;
use log::{debug, error, info};
use log::{debug, error, info, warn};
use memory::{
gc::{self, GcRuntime},
type_table::TypeTable,
Expand Down Expand Up @@ -379,6 +379,7 @@ impl Runtime {
)
}

let mut requires_relink = false;
while let Ok(event) = self.watcher_rx.try_recv() {
if let Some(path) = event.path {
let op = event.op.expect("Invalid event.");
Expand All @@ -390,18 +391,7 @@ impl Runtime {
if op.contains(notify::op::REMOVE) {
debug!("Lockfile deleted");

match relink_assemblies(self) {
Ok((dispatch_table, type_table)) => {
info!("Succesfully reloaded assemblies.");

self.dispatch_table = dispatch_table;
self.type_table = type_table;
self.assemblies_to_relink.clear();

return true;
}
Err(e) => error!("Failed to relink assemblies, due to {}.", e),
}
requires_relink = true;
}
} else {
let path = path.canonicalize().unwrap_or_else(|_| {
Expand All @@ -416,14 +406,35 @@ impl Runtime {
} else {
self.renamed_files.insert(cookie, path);
}
} else if op.contains(notify::op::WRITE) {
} else if op.intersects(
notify::op::CREATE | notify::op::WRITE | notify::op::CLOSE_WRITE,
) {
// TODO: don't overwrite existing
self.assemblies_to_relink.push_back((path.clone(), path));
}
}
}
}

if requires_relink {
if self.assemblies_to_relink.is_empty() {
debug!("The compiler didn't write a munlib.");
} else {
match relink_assemblies(self) {
Ok((dispatch_table, type_table)) => {
info!("Succesfully reloaded assemblies.");

self.dispatch_table = dispatch_table;
self.type_table = type_table;
self.assemblies_to_relink.clear();

return true;
}
Err(e) => error!("Failed to relink assemblies, due to {}.", e),
}
}
}

false
}

Expand Down
10 changes: 5 additions & 5 deletions crates/mun_runtime/tests/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,23 +327,23 @@ fn map_struct_cast_fields1() {
);
assert_eq!(
foo_struct.as_ref(&driver.runtime).get::<u16>("0").unwrap(),
a.into()
u16::from(a)
);
assert_eq!(
foo_struct.as_ref(&driver.runtime).get::<i32>("1").unwrap(),
b.into()
i32::from(b)
);
assert_eq!(
foo_struct.as_ref(&driver.runtime).get::<u64>("2").unwrap(),
c.into()
u64::from(c)
);
assert_eq!(
foo_struct.as_ref(&driver.runtime).get::<i128>("3").unwrap(),
d.into()
);
assert_eq!(
foo_struct.as_ref(&driver.runtime).get::<f64>("4").unwrap(),
e.into()
f64::from(e)
);
}

Expand Down Expand Up @@ -625,7 +625,7 @@ fn map_struct_all() {
);
assert_eq!(
foo_struct.as_ref(&driver.runtime).get::<i64>("d").unwrap(),
d.into()
i64::from(d)
);
assert_eq!(
foo_struct.as_ref(&driver.runtime).get::<i32>("e").unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions crates/mun_target/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ mod apple_sdk_base;
mod linux_base;
mod windows_msvc_base;

use crate::abi::Endian;
use crate::host_triple;
use crate::{abi::Endian, host_triple};

#[derive(Debug, Clone, Copy, Eq, Ord, PartialOrd, PartialEq, Hash)]
pub enum LinkerFlavor {
Expand Down Expand Up @@ -137,6 +136,7 @@ supported_targets!(
("x86_64-apple-ios", x86_64_apple_ios),
("x86_64-pc-windows-msvc", x86_64_pc_windows_msvc),
("x86_64-unknown-linux-gnu", x86_64_unknown_linux_gnu),
("aarch64-apple-darwin", aarch64_apple_darwin),
("aarch64-apple-ios", aarch64_apple_ios),
("aarch64-apple-ios-sim", aarch64_apple_ios_sim),
);
Expand Down
22 changes: 22 additions & 0 deletions crates/mun_target/src/spec/aarch64_apple_darwin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
// Clang automatically chooses a more specific target based on
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
// correctly, we do too.
let arch = "arm64";
let llvm_target = super::apple_base::ios_llvm_target(arch);
let (major, minor) = super::apple_base::macos_deployment_target(arch);

Target {
llvm_target,
pointer_width: 64,
arch: "aarch64".into(),
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
options: TargetOptions {
cpu: "apple-a14".into(),
min_os_version: Some((major, minor, 0)),
.. super::apple_base::opts("macos")
},
}
}
1 change: 1 addition & 0 deletions crates/mun_target/src/spec/apple_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub fn opts(os: &'static str) -> TargetOptions {
vendor: "apple".into(),
linker_flavor: LinkerFlavor::Ld64,
dll_prefix: "lib".to_string(),
is_like_osx: os == "macos",
..Default::default()
}
}
Expand Down

0 comments on commit 8aaf3f2

Please sign in to comment.