Clone wiki

goios / CrossCompilingOnMacOSX

Cross Compiling on Mac OS X

I assume the compiler is in PLAT=/Platforms/iPhoneOS.platform/Developer and SDK=iPhoneOS5.0.sdk, you should change these environment variables. The specific SDK version should not matter, but I've tested only in iPhoneOS5.0.sdk.


Host (Mac OS X)

  • Python
  • perl
  • mecurial
  • Xcode and iPhoneOS SDK

Device (only for test)

  • perl
  • python
  • sshd
  • sed, awk etc.

Cross Compiling

1, Update repo

hg clone
# OR, if you've already done cloning, you can just fetch+update
hg fetch
hg update ios # make sure you are on the ios branch

2, Setting up enviroment

# Paths, you might want to adjust these
export GOROOT=/path/to/your/goios
export PLAT=/Platforms/iPhoneOS.platform/Developer
export SDK=iPhoneOS5.0.sdk
# Others, these won't need any adjustments
export GOBIN=$GOROOT/bin
export GOOS=darwin
export GOARCH=arm
unset GOHOSTARCH # we are first compiling for Darwin/x86
export GOHOSTOS=darwin
export USE_GO_TOOL=false # because we are cross-compiling

3, Go

cd $GOROOT/src
# fix iPhoneSDK5.0's header bug
# usr/include/time.h:107:68: error: machine/_limits.h: No such file or directory
sudo touch $PLAT/SDKs/$SDK/usr/include/machine/_limits.h
# Go on! This is really fast~
# step 1: build host compiler and target packages
# step 2: re-build target compiler
export GOHOSTARCH=arm
#  update quietgcc
XCC="$PLAT/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 -isysroot $PLAT/SDKs/$SDK/"
sed -e "s|@CC@|$XCC|" < quietgcc.bash > ../bin/quietgcc
#  build all cmds
for i in lib9 libbio libmach cmd; do
  ../bin/gomake -C $i clean install

4, (Optional) Test

# Copy the entire repo to your iDevice
scp -r /path/to/your/goios mobile@iDevice:/path/to/your/iDevice/goios
ssh mobile@iDevice # ssh to your iDevices, and all other testing commands
                   # are all executed there

From now on, refer to HowToTest for details.


Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.