GitHub Actions Runner Image - boost for macOS arm64 - macos

How do I deploy boost for arm64 to a GitHub Actions Runner Image under macOS?
I am using Github Actions to build my project, which depends on boost.
As far as I can tell, when I set the YAML label to macos-11, the runner image itself is intel.
For my x86_64 build, I simply say
brew install boost
And the job can then go on to compile and link my own code successfully.
If I understand correctly, it is not possible to use brew to install boost arm64 binaries to a macOS intel machine.
Maybe I could build boost from source using something like
./bootstrap.sh
./b2 install
What flags would I pass to tell it to cross compile the arm64 binaries?
Edit: I found the solution and posted the answer below, stack overflow tells me that I do not have enough karma to mark my own answer as accepted.

At the bottom of this page...
B2 4.7.1 MacOS Armv8 package bundles x86_64 binary
...it says:
./b2 architecture=arm address-model=64 -s NO_LZMA=1 -s NO_ZSTD=1 abi=aapcs
That worked for me. The entire step that I have on github actions is:
- name: Boost
run: |
curl -O -L https://boostorg.jfrog.io/artifactory/main/release/1.80.0/source/boost_1_80_0.tar.gz
tar xfz boost_1_80_0.tar.gz
cd boost_1_80_0
./bootstrap.sh
./b2 architecture=arm address-model=64 -s NO_LZMA=1 -s NO_ZSTD=1 abi=aapcs install
lipo /usr/local/lib/libboost_*.dylib -info

Related

How to build an application for both architectures depending on some external library OR to install library for both architectures?

I have a Mac which architecture is:
$ arch
arm64
(it supports x86_64 and aarch64).
And I have installed openssl library with brew tool. Now I try to build my application for x86_64 platform (it's Haskell application and the build script is large and complex, so I cannot show it here) and I get an error:
...
<command line>: dlopen(/MyWork/.stack/snapshots/x86_64-osx/b1d675598b9b6c5f516e03f82c45d01becd6003e6128005b2b4acb8628b0f350/9.2.5/lib/x86_64-osx-ghc-9.2.5/libHSHsOpenSSL-0.11.7.2-1JX1qBi8YfpGDjk1ra3OXq-ghc9.2.5.dylib, 0x0005): symbol not found in flat namespace '_DSA_free'
...
However, it works fine for aarch64 platform. After little research I see that my OpenSSL libraries are:
$ file /opt/homebrew/opt/openssl#3/3.0.7/lib/libssl.3.dylib
/opt/homebrew/opt/openssl#3/3.0.7/lib/libssl.3.dylib: Mach-O 64-bit dynamically linked shared library arm64
which seems that it is a library for arm64 and not x86_64, so maybe this is the reason of the error "symbol not found in flat namespace '_DSA_free'".
How to fix it? I guess I need to install the second openssl - for x86_64, I tried arch -x86_64 brew install openssl but I get:
Warning: openssl#3 3.0.7 is already installed and up-to-date.
To reinstall 3.0.7, run:
brew reinstall openssl#3
which makes sense - it is installed already (but for arm64).
How to fix/workaround this problem, so to be able to build the application for both platform while it depends on external libraries like openssl? Maybe there is a way to install openssl for both platform?
EDIT:
Currently I found 2 solutions:
to install libraries from sources setting prefix=/unique/folder/for/arch and to prefix ./configure ..., make, make install by arch -ARCH (where ARCH is x86_64 or arm64).
Another way is to have 2nd Homebrew, it's described here

Compile a Rust program to an exe using an M1 mac?

I have written a program in Rust on my M1 Mac, and compiled it to a Unix executable just fine. Now I want to compile it to a Windows executable as well. I first tried
$ cargo target add x86_64-pc-windows-gnu
$ cargo build --release --target=x86_64-pc-windows-gnu
I got the error message:
error: linker x86_64-w64-mingw32-gcc not found
so I tried
$ brew install mingw-w64
according to this, and got the error:
Error: mingw-w64: no bottle available!
I looked on formulae.brew.sh and it seems that mingw-w64 isn't supported for M1, only Intel.
How can I compile an exe from rust using my M1 Mac?
Solution 1:
You can install/add the targets using these commands :
rustup target add x86_64-pc-windows-gnu
rustup toolchain install stable-x86_64-pc-windows-gnu
then you can target windows from your mac:
cargo build --release --target=x86_64-pc-windows-gnu
Solution 2:
Simply use docker!
FROM mcr.microsoft.com/windows/servercore:ltsc2019
// install rust
COPY project c:/project
RUN cd c:/project && cargo build --release
Solution 3:
there is also Cross. you can use this for cross-compilation:
https://github.com/rust-embedded/cross
I'm going to jump in with a couple newer solutions that worked really well for me:
cargo-zigbuild
Targets (*-pc-windows-gnu afaik):
i686-pc-windows-gnu
x86_64-pc-windows-gnu
cargo-zigbuild also supports cross-compiling to other platforms out of the box as well, with no containerization needed!
Quick example:
brew install zig
cargo install cargo-zigbuild
cargo zigbuild --target x86_64-pc-windows-gnu -r
cargo-xwin
Targets (*-msvc afaik):
aarch64-pc-windows-msvc
i586-pc-windows-msvc
i686-pc-windows-msvc
x86_64-pc-windows-msvc
Quick example:
cargo install cargo-xwin
cargo xwin build --target x86_64-pc-windows-msvc -r
Which one do I pick?
See: Difference between the gnu and msvc toolchains?
TL;DR: Use msvc/cargo-xwin for "more native" windows binaries (that are smaller in size) & use gnu/cargo-zigbuild to help porting over a linux-specific application.

How to Compile mingw-w64-crt

I'm on Windows 10 and using the latest version of MSYS2 (with gcc installed: pacman -S gcc)
I'm trying to compile mingw-w64-headers and mingw-w64-crt from mingw-w64-v7.0.0
Inside of my MSYS2 installation directory C:\msys2 I have created the folder mingw-w64 which I reference in the prefix argument below.
To compile each of these I use the same steps (replace name of library where appropriate):
mkdir mingw-w64-crt && cd mingw-w64-crt
../mingw-w64-v7.0.0/mingw-w64-crt/configure --prefix=/mingw-w64
make
make install
This works for mingw-w64-headers however for mingw-w64-crt I encounter errors at the make step. Specifically: incompatible types when assigning to type 'mbstate_t' {aka 'struct anonymous'} from type 'int'. A more detailed error image can be found here.
I would appreciate some guidance as to how to proceed.
I suggest that you just open one of MSYS2's MinGW environments (by running mingw32.exe or mingw64.exe) and then install the complete MinGW-w64 toolchain by running this:
pacman -S $MINGW_PACKAGE_PREFIX-toolchain
The toolchain includes GCC, the MinGW-w64 libraries, and the MinGW-w64 headers. If those prebuilt MinGW-w64 things are good enough for you, then you're done.
If you want to compile your own MinGW-w64, then should be able to use the environment you just installed to do it. To double-check that you are using the right toolchain, run which gcc and make sure it returns /mingw64/bin/gcc or /mingw32/bin/gcc.
Performing the following has allowed me to successfully compile:
pacman -S $MINGW_PACKAGE_PREFIX-toolchain
mkdir mingw-w64-crt && cd mingw-w64-crt
../mingw-w64-v7.0.0/mingw-w64-crt/configure --prefix=/mingw-w64 --with-sysroot=/mingw64
make -j %NUMBER_OF_PROCESSORS%
make install

Cant build V8 with GYP successfully on Mac OSX

I followed V8 Build Instructions from here
Here are the steps that I'm following to build V8 on Mac OSX.
1. git clone git://github.com/v8/v8.git v8-src && cd v8-src
2. make dependencies
3. make x64 -j8 library=shared snapshot=on console=readline
But I do not see out/x64.release/obj.target/tools/gyp/libv8_base.x64.a (or snapshot.a)
The Folder only contains js2c.stamp
Here is the Gist: Build Output
What am I doing wrong ..
Ok, the documentation specifies the location for Linux Machines. For Mac OSX, these files are here :
out/x64.release/libv8_base.x64.a (& snapshot.a)
Finally, compile your C++ Module, by linking V8, as below:
g++ -Iinclude test.cc -o test out/x64.release/libv8_{base.x64,snapshot}.a -lpthread

compile Boost as static Universal binary lib

I want to have a static Universal binary lib of Boost. (Preferable the latest stable version, that is 1.43.0, or newer.)
I found many Google hits with similar problems and possible solutions. However, most of them seems outdated. Also none of them really worked.
Right now, I am trying
sudo ./bjam --toolset=darwin --link=static --threading=multi \
--architecture=combined --address-model=32_64 \
--macosx-version=10.4 --macosx-version-min=10.4 \
install
That compiles and install fine. However, the produced binaries seems broken.
az#ip245 47 (openlierox) %file /usr/local/lib/libboost_signals.a
/usr/local/lib/libboost_signals.a: current ar archive random library
az#ip245 49 (openlierox) %lipo -info /usr/local/lib/libboost_signals.a
input file /usr/local/lib/libboost_signals.a is not a fat file
Non-fat file: /usr/local/lib/libboost_signals.a is architecture: x86_64
Edit: It seems that the command was wrong and I must remove the "--" for most options. So the command I am trying now (-a just means to rebuild all):
sudo ./bjam -a toolset=darwin link=static threading=multi \
architecture=combined address-model=32_64 \
macosx-version=10.4 macosx-version-min=10.4 \
install
However, this gives many strange errors (what I already had earlier), all like this:
darwin.compile.c++.pch bin.v2/libs/math/build/darwin-4.2.1/release/address-model-32_64/architecture-combined/link-static/macosx-version-min-10.4/macosx-version-10.4/threading-multi/../src/tr1/pch.hpp.gch
In file included from ./boost/math/special_functions/acosh.hpp:18,
from ./boost/math/special_functions.hpp:15,
from libs/math/build/../src/tr1/pch.hpp:9:
./boost/config/no_tr1/cmath.hpp:21:19: error: cmath: No such file or directory
This could be another problem I have when building Universal binaries: g++ on MacOSX doesn't work with -arch ppc64
I found the problem. It seems that the MacOSX 10.4 SDK is missing a bunch of symlinks for GCC 4.2.
Use this as a test case:
g++ on MacOSX doesn't work with -arch ppc64
It will report multiple errors with GCC 4.2 (missing C++ includes, missing C includes, missing libs). In all cases, you can just fix that by setting a symlink. Search in your SDK for the file and just set the symlink in the same way it is in the MacOSX 10.5 SDK.
After that, it all just worked.
We use Boost compiled for 10.4 here at work. We don't use GCC 4.2 on it though, rather we use GCC 4.0 as Apple's GCC 4.2 is not supported for the MacOS 10.4 SDK. To accomplish this you need a bjam user config file, eg. user-config-darwin.jam. Here's the contents of ours. Modify to your heart's content:
# Boost.Build Configuration
# Compiler configuration
using darwin : 8.11 : /usr/bin/g++-4.0 :
<architecture>"combined"
<address-model>"32" # this can be changed to 32_64 for 32/64 universal builds
<macosx-version>"10.4"
<macosx-version-min>"10.4"
# <root>"/Developer"
<compileflags>""
<linkflags>"" ;
Then, you need to tell bjam to use the user config jam file when compiling:
bjam --user-config=user-config-darwin.jam ... (your other options go here) ...
Now you don't have to mess with symlinks in the system SDK directories.
To build 4-way universal boost static binaries on OSX 10.6 I do the following:
Download boost from the boost website.
Extract the archive and cd into the boost_1_xx_0 folder (where xx is the version of boost you are using).
Run:
./bootstrap.sh and then
./bjam macosx-version=10.6 macosx-version-min=10.4 architecture=combined threading=multi link=static address-model=32_64
This will compile everything except for Boost.MPI (which requires the --with-mpi option). The build products get put in ./stage

Resources