Skip to content

Commit 0064800

Browse files
authored
Merge pull request #61 from cortex-command-community/macos-crosscompile
Macos crosscompile
2 parents 9198bd0 + 92e5eb0 commit 0064800

File tree

7 files changed

+251
-30
lines changed

7 files changed

+251
-30
lines changed

.github/actions/osxcross/action.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: "Setup osxcross"
2+
author: mbround18
3+
description: Setup osxcross for rust/other compilation projects.
4+
branding:
5+
icon: 'aperture'
6+
color: 'green'
7+
8+
9+
inputs:
10+
osx-version:
11+
description: "Version of osx to use."
12+
required: true
13+
14+
outputs:
15+
legacy-ssl:
16+
value: ${{steps.gen_configs.outputs.legacy-ssl}}
17+
meson-osxcross:
18+
value: ${{steps.gen_configs.outputs.meson-osxcross}}
19+
20+
runs:
21+
using: "composite"
22+
steps:
23+
- shell: bash
24+
run: |
25+
mkdir -p $GITHUB_ACTION_PATH/osxcross
26+
echo "OSXCROSS_FOLDER=$(echo "$GITHUB_ACTION_PATH/osxcross" | sed 's/\.\/*//g')" >> $GITHUB_ENV
27+
28+
29+
- uses: actions/checkout@v4
30+
with:
31+
repository: tpoechtrager/osxcross
32+
path: ${{env.OSXCROSS_FOLDER}}
33+
34+
- shell: bash
35+
id: target
36+
run: |
37+
repeat(){
38+
for i in {1..90}; do echo -n "$1"; done
39+
}
40+
41+
echo "::group::Disclaimer Click Here for Info"
42+
echo ""
43+
repeat "-"
44+
echo ""
45+
echo "The first time you run this it will take upwards of 9 minutes to compile. Subsequent builds are cached."
46+
echo ""
47+
repeat "-"
48+
echo ""
49+
echo "::endgroup::"
50+
51+
52+
echo "::group::Installing Deps"
53+
54+
sudo apt-get update
55+
sudo apt-get install --no-install-recommends -y -qq clang gcc g++ zlib1g-dev libmpc-dev libmpfr-dev libgmp-dev cmake libxml2-dev libssl-dev xz-utils
56+
echo "::endgroup::"
57+
58+
# Check setup for osx version
59+
echo "::group::Fetching macosx SDK"
60+
FILE_NAME="MacOSX${{ inputs.osx-version }}.sdk.tar.xz"
61+
62+
# Check joseluisq/macosx-sdks for release
63+
wget -nc "https://github.com/joseluisq/macosx-sdks/releases/download/${{ inputs.osx-version }}/${FILE_NAME}" -O "$OSXCROSS_FOLDER/tarballs/${FILE_NAME}"
64+
echo "::endgroup::"
65+
66+
echo "OSXCROSS_TARGET=${OSXCROSS_FOLDER}/target" >> $GITHUB_ENV
67+
68+
- uses: actions/cache@v4
69+
id: cache
70+
with:
71+
key: ${{ runner.os }}-osxcross-${{ inputs.osx-version }}
72+
path: |
73+
${{ env.OSXCROSS_TARGET }}
74+
75+
76+
- shell: bash
77+
if: steps.cache.outputs.cache-hit != 'true'
78+
env:
79+
SDK_VERSION: "${{ inputs.osx-version }}"
80+
UNATTENDED: "yes"
81+
run: |
82+
cd ${OSXCROSS_FOLDER}
83+
echo "::group::Build osxcross"
84+
./build.sh
85+
echo "::endgroup::"
86+
echo "::group::Build GCC"
87+
./build_gcc.sh
88+
echo "::endgroup::"
89+
90+
- shell: bash
91+
id: gen_configs
92+
run: |
93+
echo "::group::Setting up Bin files"
94+
OSXCROSS_FOLDER="$(echo "${GITHUB_ACTION_PATH}/osxcross" | sed 's/\.\/*//g')"
95+
echo "OSXCROSS Folder = ${OSXCROSS_FOLDER}"
96+
97+
if [ ! -d "$OSXCROSS_FOLDER/target/bin" ]; then
98+
echo "Error! Failed to find ${OSXCROSS_FOLDER}/target/bin folder!"
99+
exit 1
100+
else
101+
if hash sudo 2>/dev/null; then
102+
sudo chmod +x $OSXCROSS_FOLDER/target/bin/*
103+
else
104+
chmod +x $OSXCROSS_FOLDER/target/bin/*
105+
fi
106+
fi
107+
echo "::endgroup::"
108+
109+
echo "::group::Finding Arch Name"
110+
echo "$OSXCROSS_FOLDER/target/bin" >> $GITHUB_PATH
111+
ARCH_TARGET="$(ls $OSXCROSS_FOLDER/target | grep apple)"
112+
echo "::endgroup::"
113+
114+
ln -sf ${ARCH_TARGET}-otool ${OSXCROSS_TARGET}/bin/otool
115+
ln -sf ${ARCH_TARGET}-install_name_tool ${OSXCROSS_TARGET}/bin/install_name_tool
116+
117+
echo "::group::Write meson cross file"
118+
cat << EOF > $OSXCROSS_FOLDER/meson_osxcross.txt
119+
[constants]
120+
arch = '${ARCH_TARGET}'
121+
[binaries]
122+
c = ['ccache', arch + '-gcc']
123+
cpp = ['ccache', arch + '-g++']
124+
strip = arch + '-strip'
125+
pkg-config = arch + '-pkg-config'
126+
ranlib = arch + '-gcc-ranlib'
127+
ar = arch + '-gcc-ar'
128+
129+
[host_machine]
130+
system = 'darwin'
131+
cpu_family = 'x86_64'
132+
cpu = 'x86_64'
133+
endian = 'little'
134+
EOF
135+
echo "::endgroup::"
136+
137+
echo "meson-osxcross=${OSXCROSS_FOLDER}/meson_osxcross.txt" >> $GITHUB_OUTPUT
138+
139+
- shell: bash
140+
run: |
141+
OUT=$(patch -N -i ${GITHUB_ACTION_PATH}/macports.patch ${OSXCROSS_FOLDER}/target/bin/osxcross-macports) || echo "${OUT}" | grep "Skipping patch" -q || (echo "$OUT" && false);
142+
143+
- uses: actions/checkout@v4
144+
with:
145+
repository: auriamg/macdylibbundler
146+
path: ${{env.OSXCROSS_FOLDER}}/dylibbundler
147+
148+
- shell: bash
149+
run: |
150+
echo "::group::Install dylibbundler"
151+
cd ${OSXCROSS_FOLDER}/dylibbundler
152+
make
153+
echo "${OSXCROSS_FOLDER}/dylibbundler" >> $GITHUB_PATH
154+
echo "::endgroup::"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/tools/osxcross-macports b/tools/osxcross-macports
2+
index 3e87735..5c48e4e 100755
3+
--- a/tools/osxcross-macports
4+
+++ b/tools/osxcross-macports
5+
@@ -250,8 +250,10 @@ verifyFileIntegrity()
6+
getFile $PUBKEYURL "$PUBKEY"
7+
fi
8+
9+
- local rmd160=$(openssl rmd160 "$PUBKEY" | awk '{print $2}')
10+
- local sha1=$(openssl sha1 "$PUBKEY" | awk '{print $2}')
11+
+ errorMsg "set rmd160"
12+
+ local rmd160=$(openssl rmd160 -provider legacy "$PUBKEY" | awk '{print $2}')
13+
+ errorMsg "set sha1"
14+
+ local sha1=$(openssl sha1 "$PUBKEY" | awk '{print $2}')
15+
16+
if [ "$rmd160" != "$PUBKEYRMD160" -o "$sha1" != "$PUBKEYSHA1" ]; then
17+
errorMsg "invalid macports public key (hash check failed)"
18+
@@ -262,7 +264,7 @@ verifyFileIntegrity()
19+
20+
set +e
21+
22+
- openssl dgst -ripemd160 -verify "$PUBKEY" -signature \
23+
+ openssl dgst -provider legacy -provider default -ripemd160 -verify "$PUBKEY" -signature \
24+
"$CACHE/$file.rmd160" "$CACHE/$file" 1>/dev/null
25+
26+
if [ $? -ne 0 ]; then

.github/workflows/meson.yml

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ on:
2929
new_release_version:
3030
type: string
3131
required: false
32+
osx-version:
33+
type: string
34+
required: false
35+
default: "11.1"
36+
macosx-deployment-target:
37+
type: string
38+
required: false
39+
default: "10.15"
3240

3341
# Triggers the workflow when called by a top-level workflow
3442
workflow_call:
@@ -48,6 +56,14 @@ on:
4856
new_release_version:
4957
type: string
5058
required: false
59+
osx-version:
60+
type: string
61+
required: false
62+
default: "11.1"
63+
macosx-deployment-target:
64+
type: string
65+
required: false
66+
default: "10.15"
5167

5268
jobs:
5369
build-linux:
@@ -56,8 +72,10 @@ jobs:
5672

5773
steps:
5874
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
59-
- uses: actions/checkout@v3
60-
- uses: actions/setup-python@v3
75+
- uses: actions/checkout@v4
76+
- uses: actions/setup-python@v5
77+
with:
78+
python-version: "3.x"
6179

6280
- name: Install Dependencies
6381
run: |
@@ -66,7 +84,7 @@ jobs:
6684
sudo pip install meson
6785
6886
- name: ccache
69-
uses: hendrikmuhs/[email protected]
87+
uses: hendrikmuhs/[email protected].11
7088
with:
7189
key: ${{ github.job }}-${{ matrix.os }}
7290

@@ -82,14 +100,14 @@ jobs:
82100
CC: "ccache gcc"
83101
CXX: "ccache g++"
84102
run: |
85-
meson setup --buildtype=${{inputs.build_type}} -Ddebug_type=${{inputs.debug_level}} -Db_lto=true build
103+
meson setup --buildtype=${{inputs.build_type}} -Ddebug_type=${{inputs.debug_level}} -Db_lto=false build
86104
87105
- name: Configure for AppImage
88106
if: ${{inputs.upload_artefacts}}
89107
env:
90108
CC: "ccache gcc"
91109
CXX: "ccache g++"
92-
run: meson configure -Dinstall_data=false -Dinstall_runner=false -Dfmod_dir=/usr/lib/ --prefix=/usr/ build
110+
run: meson configure -Db_lto=true -Dinstall_data=false -Dinstall_runner=false -Dfmod_dir=/usr/lib/ --prefix=/usr/ build
93111

94112
- name: Build
95113
env:
@@ -123,27 +141,47 @@ jobs:
123141
124142
- name: Upload Appimage
125143
if: ${{inputs.upload_artefacts}}
126-
uses: actions/upload-artifact@v3
144+
uses: actions/upload-artifact@v4
127145
with:
128146
name: CortexCommand (Linux)
129147
path: CortexCommand.AppImage
130148
if-no-files-found: error
131149

132150
build-macos:
133-
runs-on: macos-11
151+
runs-on: ubuntu-latest
134152
name: MacOS Build
135153

136154
env:
137-
GCC_VERSION: "13"
138-
MACOSX_DEPLOYMENT_TARGET: 10.15
155+
MACOSX_DEPLOYMENT_TARGET: ${{inputs.macosx-deployment-target}}
139156
steps:
140-
- uses: actions/checkout@v3
141-
- uses: actions/setup-python@v3
157+
- uses: actions/checkout@v4
158+
- uses: actions/setup-python@v5
159+
with:
160+
python-version: "3.x"
142161

143-
- name: "Install Dependencies"
144-
uses: melusina-org/setup-macports@v1
162+
- name: "Install Osxcross"
163+
id: osxcross
164+
uses: ./.github/actions/osxcross
145165
with:
146-
parameters: ".github/parameters/macports.yml"
166+
osx-version: ${{ inputs.osx-version }}
167+
168+
- name: "Cache Dependencies"
169+
uses: actions/cache@v4
170+
with:
171+
key: ${{runner.os}}-${{inputs.osx-version}}-macports
172+
path: ${{env.OSXCROSS_FOLDER}}/target/macports
173+
174+
- name: "Install Dependencies"
175+
env:
176+
OSXCROSS_MACPORTS_MIRROR: "https://packages.macports.org"
177+
run: |
178+
echo "::group::Installing mac deps"
179+
omp install libsdl2 onetbb lz4 libpng minizip luajit flac
180+
echo "OSXCROSS_PKG_CONFIG_PATH=${{env.OSXCROSS_TARGET}}/macports/pkgs/opt/local/libexec/onetbb/lib/pkgconfig" >> $GITHUB_ENV
181+
echo "::endgroup::"
182+
echo "::group::Installing meson"
183+
pip install meson ninja
184+
echo "::endgroup::"
147185
148186
- name: Set Version
149187
if: ${{inputs.new_release_version}}
@@ -153,48 +191,43 @@ jobs:
153191
github_token: ${{ secrets.GITHUB_TOKEN }}
154192

155193
- name: ccache
156-
uses: hendrikmuhs/[email protected]
194+
uses: hendrikmuhs/[email protected].11
157195
with:
158196
key: ${{ github.job }}-${{ matrix.os }}
159197

160198
- name: Setup Meson
161199
env:
162-
CC: "ccache gcc-${{env.GCC_VERSION}}"
163-
CXX: "ccache g++-${{env.GCC_VERSION}}"
164200
LDFLAGS: "-static-libgcc -static-libstdc++"
165201
run: |
166-
meson setup --buildtype=${{inputs.build_type}} -Ddebug_type=${{inputs.debug_level}} -Db_lto=false build
202+
meson setup --cross-file=${{steps.osxcross.outputs.meson-osxcross}} --buildtype=${{inputs.build_type}} -Ddebug_type=${{inputs.debug_level}} -Db_lto=false build
167203
168204
- name: Configure for App Bundle
169205
if: ${{inputs.upload_artefacts}}
170206
env:
171-
CC: "ccache gcc-${{env.GCC_VERSION}}"
172-
CXX: "ccache g++-${{env.GCC_VERSION}}"
173207
LDFLAGS: "-static-libgcc -static-libstdc++"
174208
run: |
175209
meson configure \
176210
-Dinstall_data=false -Dinstall_runner=false -Dfmod_dir=Contents/Frameworks \
177211
--bindir=Contents/MacOS \
178212
--prefix="/" \
213+
-Ddylibbundler_args="-ns -s ${{env.OSXCROSS_TARGET}}/macports/pkgs/opt/local/lib/ \
214+
-s ${{env.OSXCROSS_TARGET}}/macports/pkgs/opt/local/libexec/onetbb/lib/" \
179215
build
180216
181217
- name: Build
182218
env:
183-
CC: "ccache gcc-${{env.GCC_VERSION}}"
184-
CXX: "ccache g++-${{env.GCC_VERSION}}"
185219
LDFLAGS: "-static-libgcc -static-libstdc++"
186220
run: |
187221
meson compile -C build
188222
189223
- name: Create App Bundle
190224
if: ${{inputs.upload_artefacts}}
191225
run: |
192-
DESTDIR="/tmp/Cortex Command.app" meson install -C build
226+
meson install --destdir="/tmp/Cortex Command.app" -C build
193227
194228
- name: Tar files
195229
if: ${{inputs.upload_artefacts}}
196230
run: |
197-
tree /tmp/
198231
cd /tmp/
199232
tar -cvf CortexCommand.tar "Cortex Command.app"
200233
@@ -204,7 +237,7 @@ jobs:
204237

205238
- name: Artifact Deploy
206239
if: ${{inputs.upload_artefacts}}
207-
uses: actions/upload-artifact@v3
240+
uses: actions/upload-artifact@v4
208241
with:
209242
name: CortexCommand (macOS)
210243
path: |
@@ -216,8 +249,10 @@ jobs:
216249
name: Windows Build
217250

218251
steps:
219-
- uses: actions/checkout@v3
220-
- uses: actions/setup-python@v3
252+
- uses: actions/checkout@v4
253+
- uses: actions/setup-python@v5
254+
with:
255+
python-version: "3.x"
221256

222257
- name: Install Dependencies
223258
run: |

Resources/bundle_dylibs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
dylibbundler -od -b -x "${MESON_INSTALL_DESTDIR_PREFIX}/Contents/MacOS/${1}" \
44
-d "${MESON_INSTALL_DESTDIR_PREFIX}/Contents/Frameworks" \
55
-p "@executable_path/../Frameworks" \
6-
-s "${MESON_SOURCE_ROOT}/external/lib/macos"
6+
-s "${MESON_SOURCE_ROOT}/external/lib/macos" ${2}

0 commit comments

Comments
 (0)