-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Make ImHexbuildable for MacOS arm64 (#1414)
- Loading branch information
Showing
6 changed files
with
270 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
# see arm64.crosscompile.Dockerfile | ||
FROM crosscompile as build | ||
|
||
ENV MACOSX_DEPLOYMENT_TARGET 12.1 | ||
|
||
# -- DOWNLOADING STUFF | ||
|
||
## Install make | ||
RUN --mount=type=cache,target=/var/lib/apt/lists/ apt update && apt install -y make | ||
|
||
## fix environment | ||
### add install_name_tool for cmake command that won't have the right env set (see PostprocessBundle.cmake function postprocess_bundle()) | ||
RUN cp /osxcross/build/cctools-port/cctools/misc/install_name_tool /usr/bin/install_name_tool | ||
### a cmake thing wants 'otool' and not '' apparently | ||
RUN cp /osxcross/target/bin/aarch64-apple-darwin23-otool /usr/bin/otool | ||
|
||
## Clone glfw | ||
RUN <<EOF | ||
set -xe | ||
if [ "$CUSTOM_GLFW" ]; then | ||
git clone https://github.com/glfw/glfw /mnt/glfw | ||
fi | ||
EOF | ||
|
||
## Assume the SDK has been removed from the image, and copy it again | ||
COPY SDK /osxcross/target/SDK | ||
|
||
## Download libmagic | ||
### Clone libmagic | ||
RUN git clone https://github.com/file/file /mnt/file | ||
### Download libmagic dependencies | ||
RUN --mount=type=cache,target=/var/lib/apt/lists/ apt install -y libtool autoconf | ||
|
||
# -- DOWNLOADING + BUILDING STUFF | ||
## Install libcurl dep | ||
RUN vcpkg install --triplet=arm-osx-mytriplet curl | ||
## Install mbedtls dep | ||
RUN vcpkg install --triplet=arm-osx-mytriplet mbedtls | ||
## Install freetype dep | ||
RUN vcpkg install --triplet=arm-osx-mytriplet freetype | ||
## Install jthread external library | ||
RUN vcpkg install --triplet=arm-osx-mytriplet josuttis-jthread | ||
|
||
## Install glfw3 dep | ||
ARG CUSTOM_GLFW | ||
RUN <<EOF | ||
set -xe | ||
if [ "$CUSTOM_GLFW" ]; then | ||
echo "Flag confirmation: using custom GLFW for software rendering" | ||
else | ||
vcpkg install --triplet=arm-osx-mytriplet glfw3 | ||
fi | ||
EOF | ||
|
||
# -- BUILDING STUFF | ||
ARG JOBS 1 | ||
ARG BUILD_TYPE Debug | ||
|
||
## Build libmagic | ||
RUN --mount=type=cache,target=/cache <<EOF | ||
ccache -zs | ||
set -xe | ||
|
||
cd /mnt/file | ||
autoreconf -is | ||
|
||
# when cross-compiling, libmagic needs to have an the same version installed in the system. | ||
# So we install it normally first | ||
./configure --prefix /usr | ||
make -j $JOBS install | ||
|
||
# Now, we cross-compile it and install it in the libraries folder | ||
CC=/osxcross/target/bin/aarch64-apple-darwin23-clang CXX=/osxcross/target/bin/aarch64-apple-darwin23-clang++ ./configure --prefix /vcpkg/installed/arm-osx-mytriplet --host $OSXCROSS_HOST | ||
make -j $JOBS | ||
make install | ||
|
||
ccache -s | ||
|
||
EOF | ||
|
||
## Patch glfw | ||
COPY --from=imhex /dist/macOS/0001-glfw-SW.patch /tmp | ||
RUN <<EOF | ||
set -xe | ||
if [ "$CUSTOM_GLFW" ]; then | ||
cd /mnt/glfw | ||
git apply /tmp/0001-glfw-SW.patch | ||
fi | ||
EOF | ||
|
||
## Build glfw | ||
RUN --mount=type=cache,target=/cache <<EOF | ||
set -xe | ||
if [ "$CUSTOM_GLFW" ]; then | ||
ccache -zs | ||
|
||
cd /mnt/glfw | ||
mkdir build | ||
cd build | ||
CC=o64-gcc CXX=o64-g++ cmake -G "Ninja" \ | ||
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \ | ||
-DBUILD_SHARED_LIBS=ON \ | ||
-DCMAKE_C_COMPILER_LAUNCHER=ccache \ | ||
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | ||
-DCMAKE_OBJC_COMPILER_LAUNCHER=ccache \ | ||
-DCMAKE_OBJCXX_COMPILER_LAUNCHER=ccache \ | ||
-DCMAKE_INSTALL_PREFIX=/vcpkg/installed/arm-osx-mytriplet \ | ||
-DVCPKG_TARGET_TRIPLET=arm-osx-mytriplet -DCMAKE_TOOLCHAIN_FILE=/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=/osxcross/target/toolchain.cmake -DCMAKE_OSX_SYSROOT=/osxcross/target/SDK/MacOSX14.0.sdk -DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 \ | ||
.. | ||
ninja -j $JOBS install | ||
|
||
ccache -s | ||
fi | ||
EOF | ||
|
||
# Build ImHex | ||
## Copy ImHex | ||
COPY --from=imhex / /mnt/ImHex | ||
## Patch ImHex with hacks | ||
# COPY toolchain.cmake.2 /osxcross/target/toolchain.cmake | ||
# Configure ImHex build | ||
RUN --mount=type=cache,target=/cache --mount=type=cache,target=/mnt/ImHex/build/_deps \ | ||
cd /mnt/ImHex && \ | ||
# compilers | ||
CC=o64-clang CXX=o64-clang++ OBJC=/osxcross/target/bin/aarch64-apple-darwin23-clang OBJCXX=/osxcross/target/bin/aarch64-apple-darwin23-clang++ \ | ||
cmake -G "Ninja" \ | ||
`# ccache flags` \ | ||
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_OBJC_COMPILER_LAUNCHER=ccache -DCMAKE_OBJCXX_COMPILER_LAUNCHER=ccache \ | ||
`# MacOS cross-compiling flags` \ | ||
-DVCPKG_TARGET_TRIPLET=arm-osx-mytriplet -DCMAKE_TOOLCHAIN_FILE=/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=/osxcross/target/toolchain.cmake -DCMAKE_OSX_SYSROOT=/osxcross/target/SDK/MacOSX14.0.sdk -DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 \ | ||
`# Override compilers for code generators` \ | ||
-DNATIVE_CMAKE_C_COMPILER=/usr/bin/clang -DNATIVE_CMAKE_CXX_COMPILER=/usr/bin/clang++ \ | ||
`# Normal ImHex flags` \ | ||
-DIMHEX_GENERATE_PACKAGE=ON -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ | ||
`# other flags` \ | ||
-DIMHEX_STRICT_WARNINGS=OFF \ | ||
-B build | ||
## Build ImHex | ||
RUN --mount=type=cache,target=/cache --mount=type=cache,target=/mnt/ImHex/build/_deps <<EOF | ||
ccache -zs | ||
set -xe | ||
|
||
cd /mnt/ImHex | ||
cmake --build build --parallel $JOBS | ||
|
||
ccache -s | ||
EOF | ||
|
||
# package ImHex | ||
## install genisoimage | ||
RUN --mount=type=cache,target=/var/lib/apt/lists/ apt install -y genisoimage | ||
## Move everything that need to be packaged inside a directory | ||
RUN <<EOF | ||
set -xe | ||
cd /mnt/ImHex/build | ||
mkdir installDir | ||
mv imhex.app installDir | ||
EOF | ||
## generate dmg file | ||
RUN cd /mnt/ImHex/build && genisoimage -V imhex.app -D -R -apple -no-pad -o imhex.dmg installDir | ||
|
||
FROM scratch | ||
COPY --from=build /mnt/ImHex/build/imhex.dmg . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# This image is is provided for reference, but a (potentially more up to date) image should be available at https://github.com/iTrooz/macos-crosscompile | ||
FROM ubuntu:22.04 | ||
|
||
ENV PATH $PATH:/osxcross/target/bin | ||
ENV LD_LIBRARY_PATH /osxcross/target/lib | ||
ENV OSXCROSS_SDK /osxcross/target/SDK/MacOSX14.0.sdk | ||
ENV OSXCROSS_TARGET darwin23 | ||
ENV OSXCROSS_TARGET_DIR /osxcross/target | ||
ENV OSXCROSS_HOST aarch64-apple-darwin23 | ||
|
||
# -- DOWNLOADING STUFF | ||
|
||
# Install common stuff | ||
RUN --mount=type=cache,target=/var/lib/apt/lists/ export DEBIAN_FRONTEND=noninteractive &&\ | ||
export TZ=Etc/UTC &&\ | ||
dpkg --add-architecture i386 &&\ | ||
apt update &&\ | ||
apt -y install lsb-release build-essential python3 python3-pip git wget zip unzip pkg-config curl ninja-build software-properties-common gnupg libssl-dev ccache | ||
|
||
# Install clang 17 | ||
RUN --mount=type=cache,target=/var/lib/apt/lists/ wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && ./llvm.sh 17 &&\ | ||
ln -s /usr/bin/clang-17 /usr/bin/clang &&\ | ||
ln -s /usr/bin/clang++-17 /usr/bin/clang++ | ||
|
||
# Install vcpkg | ||
RUN cd / &&\ | ||
git clone --depth 1 https://github.com/Microsoft/vcpkg.git vcpkg &&\ | ||
cd /vcpkg &&\ | ||
./bootstrap-vcpkg.sh -disableMetrics &&\ | ||
ln -s /vcpkg/vcpkg /usr/bin/ &&\ | ||
vcpkg install vcpkg-cmake &&\ | ||
ln -s /vcpkg/downloads/tools/cmake-*/cmake-*/bin/cmake /usr/bin/ | ||
|
||
RUN --mount=type=cache,target=/cache <<EOF | ||
## Clone osxcross | ||
set -xe | ||
git clone https://github.com/tpoechtrager/osxcross /cache/osxcross || true | ||
cd /cache/osxcross | ||
git pull | ||
cp -r /cache/osxcross /osxcross | ||
EOF | ||
|
||
RUN --mount=type=cache,target=/cache <<EOF | ||
## Download SDK | ||
set -xe | ||
wget https://github.com/joseluisq/macosx-sdks/releases/download/14.0/MacOSX14.0.sdk.tar.xz -O /cache/MacOSX14.0.sdk.tar.xz -nc || true | ||
cp /cache/MacOSX14.0.sdk.tar.xz /osxcross/tarballs | ||
EOF | ||
|
||
# Init stuff | ||
## setup ccache dir | ||
ENV CCACHE_DIR /cache/ccache | ||
|
||
# Install triplet file | ||
COPY arm-osx-mytriplet.cmake /vcpkg/triplets/community | ||
|
||
# -- BUILDING STUFF | ||
ARG JOBS 1 | ||
|
||
# Install osxcross | ||
## Build cross-compiler clang-17 | ||
RUN --mount=type=cache,target=/cache <<EOF | ||
set -xe | ||
ccache -zs | ||
|
||
cd /osxcross | ||
UNATTENDED=1 CC=/usr/lib/ccache/clang-17 CXX=/usr/lib/ccache/clang++-17 ./build.sh | ||
|
||
ccache -s | ||
EOF | ||
# Not needed, because we don't use gcc for cross-compiling anymore | ||
# ## Install dependencies for gcc-13 | ||
# RUN apt install -y gcc g++ zlib1g-dev libmpc-dev libmpfr-dev libgmp-dev | ||
# ## Build cross-compiler gcc-13 | ||
# RUN --mount=type=cache,target=/cache <<EOF | ||
# set -xe | ||
# ccache -zs | ||
|
||
# cd /osxcross | ||
# UNATTENDED=1 CC=/usr/lib/ccache/gcc CXX=/usr/lib/ccache/g++ GCC_VERSION=13.2.0 ./build_gcc.sh | ||
|
||
# ccache -s | ||
# EOF | ||
|
||
ARG DELETE_SDK=1 | ||
RUN <<EOF | ||
# Conditionally delete the SDK from the image | ||
set -xe | ||
|
||
if [ "$DELETE_SDK" ]; then | ||
rm -r /osxcross/target/SDK | ||
echo "Deleted the SDK from the image" | ||
else | ||
echo "NOT deleting the SDK from the image" | ||
fi | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters