Build Apple Silicon binary on Intel machine
We ended up solving solving this and being able to compile darwin-arm64
and debian-aarch64
binaries on GitHub Actions' x86-64 machines.
We pre-compiled all our dependencies for arm64 and linked them statically as well as dynamically.
export RELAY_DEPS_PATH=./build-deps/arm64
export PKG_CONFIG_PATH=./build-deps/arm64/lib/pkgconfig
cd ./relay-deps
TARGET=./build-deps make install
cd ./relay
phpize
./configure CFLAGS='-target arm64-apple-macos' \
--host=aarch64-apple-darwin \
--enable-relay-jemalloc-prefix
[snip...]
make
# Dynamically linked binary
cc --target=arm64-apple-darwin \
${wl}-flat_namespace ${wl}-undefined ${wl}suppress \
-o .libs/relay.so -bundle .libs/*.o \
-L$RELAY_DEPS_PATH/lib -lhiredis -ljemalloc_pic [snip...]
# re-link to standard paths
./relay-deps/utils/macos/relink.sh .libs/relay.so /usr/local/lib
cp .libs/relay.so modules/relay.so
# Build a statically linked shared object
cc --target=arm64-apple-darwin \
${wl}-flat_namespace ${wl}-undefined ${wl}suppress \
-o .libs/relay-static.so -bundle .libs/*.o \
$RELAY_DEPS_PATH/lib/libhiredis.a \
$RELAY_DEPS_PATH/lib/libjemalloc_pic.a \
[snip...]
The relink.sh
:
#!/bin/bash
set -e
printUsage() {
echo "$0 <shared-object> <prefix>"
exit 1
}
if [[ ! -f "$1" || -z "$2" ]]; then
printUsage
exit 1
fi
INFILE=$1
PREFIX=$2
links=(libjemalloc libhiredis [snip...])
if [ -z "$PREFIX" ]; then
PREFIX=libs
fi
for link in ${links[@]}; do
FROM=$(otool -L "$INFILE"|grep $link|awk '{print $1}')
FILE=$(basename -- "$FROM")
TO="$PREFIX/$FILE"
echo "$FROM -> $TO"
install_name_tool -change "$FROM" "$TO" "$1"
done
How to build an Intel binary on an M1 Mac from the command line with the standard Apple version of clang?
Intel 32 bit is not executable on macOS since Catalina. Every Mac since 2006, except the original Intel Mac mini with Core Solo processor, is 64 bit capable.
Intel:clang -o myTool-x86_64 -mmacosx-version-min=10.15 -arch x86_64 main.c
ARM64:clang -o myTool-arm64 -mmacosx-version-min=10.15 -arch arm64 main.c
FAT binary:lipo myTool-x86_64 myTool-arm64 -create -output myTool
Cross compile Go on OSX?
With Go 1.5 they seem to have improved the cross compilation process, meaning it is built in now. No ./make.bash
-ing or brew
-ing required. The process is described here but for the TLDR-ers (like me) out there: you just set the GOOS
and the GOARCH
environment variables and run the go build.
For the even lazier copy-pasters (like me) out there, do something like this if you're on a *nix system:
env GOOS=linux GOARCH=arm go build -v github.com/path/to/your/app
You even learned the env
trick, which let you set environment variables for that command only, completely free of charge.
How to compile an amd64 binary that uses C on an M1 (arm64) Mac
In my case, I also needed to set CGO_ENABLED
to true. The app now compiles fine for amd64 with GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build
(Thanks to this answer)
Compile Linux program from Mac OS X with Free Pascal
Success! If you install Fink and then say
sudo fink install fpc-i386-linux
it will install Free Pascal and everything you need to cross compile. You will then be able to say
/sw/bin/fpc -Tlinux hw.pas
and get a Linux executable.
Related Topics
Are System Calls on Windows Inherently Slower Than Linux
Watermarking Video from The Linux Command Line
Trouble with Vagrant - "404 - Not Found"
How to Check Character Encoding of a File in Linux
How to Let Users Run a Script with Root Permissions
Fork() and Stdout/Stderr to The Console from Child Processes
Is Swarm Required for Using Multi-Host Networking Feature Using Overlay in Docker
Eclipse Doesn't Use The Path Set in .Bashrc
Linux: Checking If a Socket/Pipe Is Broken Without Doing a Read()/Write()
Automatically Sync Two Amazon S3 Buckets, Besides S3Cmd
How to Send Esc/Pos Commands to Thermal Printer in Linux
Linux of Equivalent Cryptprotectmemory
Mouse and Keyboard Not Working in Qemu Emulator
Uses for This Bash Filename Extraction Technique