Skip to content
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

feat: add M1 support #444

Merged
merged 9 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
gen-syntax = "run --package tools --bin tools -- gen-syntax"
gen-runtime-capi = "run --package tools --bin tools -- gen-runtime-capi"
gen-abi = "run --package tools --bin tools -- gen-abi"

[profile.min-artifact-size-debug]
inherits = "dev"

# disable debug symbols for all packages except this one
[profile.min-artifact-size-debug.package."*"]
debug = false
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,22 @@ jobs:
CARGO_INCREMENTAL: ${{ matrix.CARGO_INCREMENTAL }}
with:
command: test
args: --doc --all-features
args: --doc --all-features --profile min-artifact-size-debug

- name: Install latest nextest release
uses: taiki-e/install-action@nextest

- run: Get-PSDrive
if: matrix.os == 'windows-latest'

- name: Test with latest nextest release
uses: actions-rs/cargo@v1
env:
RUSTFLAGS: ${{ matrix.RUSTFLAGS }}
CARGO_INCREMENTAL: ${{ matrix.CARGO_INCREMENTAL }}
with:
command: nextest
args: run --all-features --profile ci
args: run --all-features --profile ci --cargo-profile min-artifact-size-debug

test-mdbook:
name: Test mdbook
Expand Down
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)

### Changed

- Reduce workspace target folder size from 10.9 GB to 10.6 GB
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]
mun_abi = { version = "=0.4.0-dev", path = "../mun_abi" }
anyhow = { version = "1.0.31", default-features = false, features = ["std"] }
apple-codesign = { version = "0.20.0", default-features = false }
array-init = { version = "2.0.0", default-features = false }
by_address = { version = "1.0.4", default-features = false }
bytemuck = { version = "1.4.1", default-features = false }
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
33 changes: 21 additions & 12 deletions crates/mun_runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ impl Runtime {
)
}

let mut requires_relink = false;
while let Ok(Ok(event)) = self.watcher_rx.try_recv() {
for path in event.paths {
if is_lockfile(&path) {
Expand All @@ -390,18 +391,7 @@ impl Runtime {
EventKind::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;
}
_ => (),
}
Expand Down Expand Up @@ -430,6 +420,25 @@ impl Runtime {
}
}

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