Skip to content

Instantly share code, notes, and snippets.

@DrewRidley
Created June 9, 2023 20:52
Show Gist options
  • Save DrewRidley/668a4c673021b2e5aa47e08381ce7673 to your computer and use it in GitHub Desktop.
Save DrewRidley/668a4c673021b2e5aa47e08381ce7673 to your computer and use it in GitHub Desktop.
use std::process::Command;
fn main() {
let arch = "osx.13-arm64";
let aot_base = "/users/drewridley/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0-preview.4.23259.5";
let bepuvy_base = "/users/drewridley/RiderProjects/Bepuvy/Bepuvy";
let debug = false;
let required_libs = [
"/sdk/libbootstrapperdll.a",
"/sdk/libRuntime.WorkstationGC.a",
"/sdk/libstdc++compat.a",
"/sdk/libeventpipe-disabled.a",
"/framework/libSystem.Native.a",
"/framework/libSystem.IO.Compression.Native.a",
"/framework/libSystem.Net.Security.Native.a",
"/framework/libSystem.Security.Cryptography.Native.OpenSsl.a",
];
for lib_name in required_libs {
let lib_path = aot_base.to_owned() + lib_name;
println!("cargo:rustc-link-lib=static:+verbatim={}", lib_path);
}
let output = Command::new("dotnet")
.arg("publish")
.arg("/p:NativeLib=Static")
.arg("-p:IlcInstructionSet=apple-m1")
.arg("Bepuvy.csproj")
.arg("-c")
.arg(if debug {"Debug"} else {"Release"})
.arg("-r")
.arg("osx.13-arm64")
.arg("-p:PublishAot=true")
.arg("-p:EnableNativeEventPipe=false")
.arg("-p:InvariantGlobalization=true")
.arg("-p:StripSymbols=false")
.arg("-f")
.arg("net8.0")
.current_dir(bepuvy_base)
.status()
.expect("Failed to execute command");
//Where the output is:
let output_dir = bepuvy_base.to_owned() + "/bin/" + (if debug {
"Debug"
} else {
"Release"
}) + "/net8.0/" + arch + "/publish/Bepuvy.a";
if output.success() {
println!("cargo:rustc-link-lib=static:+verbatim={}", output_dir);
//println!("cargo:rustc-link-lib=objc");
//println!("cargo:rustc-link-lib=swiftCore");
// println!("cargo:rustc-link-lib=swiftFoundation");
println!("cargo:rustc-link-lib=icucore");
//println!("cargo:rustc-link-search=/usr/lib/swift");
println!("cargo:rustc-link-args=-Wl,-u,_NativeAOT_StaticInitialization");
//println!("cargo:rustc-link-arg=-Wl,-no_fixup_chains");
}
else {
panic!("Failed to build with NativeAOT: {}", output);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment