diff --git a/Makefile.toml b/Makefile.toml index c274847..101d8d8 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -7,7 +7,7 @@ RELEASE = false NO_X11 = false NO_MODULO = false EXEC_PATH = "target/debug/espanso" -BUILD_ARCH = "x86_64" # TODO: do something with this +BUILD_ARCH = "current" [env.release] DEBUG = false @@ -48,10 +48,31 @@ dependencies = ["build-windows-portable", "build-windows-installer"] # macOS +[tasks.build-macos-arm-binary] +env = { "BUILD_ARCH" = "aarch64-apple-darwin" } +run_task = [ + { name = "build-binary" } +] + +[tasks.build-macos-x86-binary] +env = { "BUILD_ARCH" = "x86_64-apple-darwin" } +run_task = [ + { name = "build-binary" } +] + +[tasks.build-universal-binary] +script = { file = "scripts/join_universal_binary.sh"} +dependencies=["build-macos-arm-binary", "build-macos-x86-binary"] + [tasks.create-bundle] script = { file = "scripts/create_bundle.sh" } dependencies=["build-binary"] +[tasks.create-universal-bundle] +env = { "EXEC_PATH" = "target/universal/espanso" } +script = { file = "scripts/create_bundle.sh" } +dependencies=["build-universal-binary"] + [tasks.run-bundle] command="target/mac/Espanso.app/Contents/MacOS/espanso" args=["${@}"] diff --git a/scripts/build_binary.rs b/scripts/build_binary.rs index 8548f06..0c17995 100644 --- a/scripts/build_binary.rs +++ b/scripts/build_binary.rs @@ -37,6 +37,12 @@ fn main() { args.push("--release"); } + let override_target_arch = envmnt::get_or("BUILD_ARCH", "current"); + if override_target_arch != "current" { + args.push("--target"); + args.push(&override_target_arch); + } + args.push("--manifest-path"); args.push("espanso/Cargo.toml"); diff --git a/scripts/create_bundle.sh b/scripts/create_bundle.sh index c81d02c..e6d119e 100644 --- a/scripts/create_bundle.sh +++ b/scripts/create_bundle.sh @@ -1,3 +1,5 @@ +set -e + TARGET_DIR=target/mac/Espanso.app rm -Rf $TARGET_DIR diff --git a/scripts/join_universal_binary.sh b/scripts/join_universal_binary.sh new file mode 100644 index 0000000..9191961 --- /dev/null +++ b/scripts/join_universal_binary.sh @@ -0,0 +1,9 @@ +set -e + +TARGET_DIR=target/universal + +rm -Rf $TARGET_DIR + +mkdir -p $TARGET_DIR + +lipo -create -output "$TARGET_DIR/espanso" ./target/x86_64-apple-darwin/release/espanso ./target/aarch64-apple-darwin/release/espanso \ No newline at end of file