Skip to content

Commit 3c1932d

Browse files
Ninja3047ekilmer
andauthored
Cross compile for m1 in ci (#958)
* add cross compilation support to build_dependencies.sh script update workflow to cross compile for m1 add arm64-osx-rel triplet * Make host triplet the release-only triplet Host triplet is really only used for providing tools that need to be run on the host, so Debug doesn't really make sense. This also saves a lot of disk space and compile time * specify system name for cross compilation * disable remill/rellic/anvil build on non x64 * Fix LLVM-15 for cross-compilation Co-authored-by: William Tan <[email protected]> Co-authored-by: Eric Kilmer <[email protected]>
1 parent 088576b commit 3c1932d

File tree

6 files changed

+73
-22
lines changed

6 files changed

+73
-22
lines changed

.github/workflows/vcpkg_ci_mac.yml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: MacOS Continuous Integration
33
env:
44
# "Source" is set in the setup-dotnet action
55
VCPKG_BINARY_SOURCES: 'clear;nuget,Source,readwrite;nugettimeout,3601'
6-
TRIPLET: 'x64-osx-rel'
76
VCPKG_DEFAULT_HOST_TRIPLET: 'x64-osx-rel'
87

98
on:
@@ -38,11 +37,15 @@ jobs:
3837
'llvm-14',
3938
'llvm-15'
4039
]
40+
target_arch: [
41+
'x64',
42+
'arm64'
43+
]
4144

4245
runs-on: ${{ matrix.os.runner }}
4346

4447
env:
45-
ARTIFACT_NAME: vcpkg_${{ matrix.os.runner }}_${{ matrix.llvm }}_xcode-${{ matrix.os.xcode }}_amd64
48+
ARTIFACT_NAME: vcpkg_${{ matrix.os.runner }}_${{ matrix.llvm }}_xcode-${{ matrix.os.xcode }}_${{ matrix.target_arch }}
4649

4750
steps:
4851
- uses: actions/checkout@v3
@@ -94,9 +97,10 @@ jobs:
9497
-source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \
9598
"${{ secrets.GITHUB_TOKEN }}"
9699
97-
./build_dependencies.sh --release --export-dir ./${{ env.ARTIFACT_NAME }} ${{ matrix.llvm }} --clean-after-build --debug
100+
./build_dependencies.sh --release --target-arch ${{ matrix.target_arch }} --export-dir ./${{ env.ARTIFACT_NAME }} ${{ matrix.llvm }} --clean-after-build --debug
98101
99102
echo "VCPKG_ROOT=$(pwd)/${{ env.ARTIFACT_NAME }}" >> $GITHUB_ENV
103+
echo "TARGET_TRIPLET=${{ matrix.target_arch }}-osx-rel" >> $GITHUB_ENV
100104
101105
- name: 'Export Packages'
102106
if: contains(env.COMMIT_MESSAGE, 'debug artifacts') || github.event.release
@@ -139,9 +143,9 @@ jobs:
139143
uses: actions/cache@v3
140144
with:
141145
path: ${{ github.workspace }}/.ccache
142-
key: ccache-${{ matrix.os.runner }}-${{ matrix.os.xcode }}-${{ matrix.llvm }}-${{ steps.ccache_prep.outputs.timestamp }}
146+
key: ccache-${{ matrix.os.runner }}-${{ matrix.os.xcode }}-${{ matrix.llvm }}-${{ matrix.target_arch }}-${{ steps.ccache_prep.outputs.timestamp }}
143147
restore-keys: |
144-
ccache-${{ matrix.os.runner }}-${{ matrix.os.xcode }}-${{ matrix.llvm }}-
148+
ccache-${{ matrix.os.runner }}-${{ matrix.os.xcode }}-${{ matrix.llvm }}-$${{ matrix.target_arch }}
145149
146150
- name: ccache Initial stats
147151
shell: bash
@@ -150,54 +154,75 @@ jobs:
150154
151155
- name: 'Rellic build'
152156
shell: 'bash'
153-
if: ${{ matrix.llvm == 'llvm-14' }}
157+
if: ${{ matrix.llvm == 'llvm-14' && matrix.target_arch == 'x64' }}
154158
run: |
155159
cd rellic
156160
mkdir -p build && cd build
157161
cmake -G Ninja \
158162
-DCMAKE_VERBOSE_MAKEFILE=ON \
159163
-DVCPKG_ROOT="${VCPKG_ROOT}" \
164+
-DVCPKG_TARGET_TRIPLET=${TARGET_TRIPLET} \
165+
-DCMAKE_OSX_ARCHITECTURES=${{ matrix.target_arch == 'x64' && 'x86_64' || matrix.target_arch }} \
160166
-DCMAKE_INSTALL_PREFIX="$(pwd)/install" \
161167
..
162168
cmake --build .
163169
cmake --build . --target install
164-
../scripts/roundtrip.py ./tools/rellic-decomp ../tests/tools/decomp "${VCPKG_ROOT}/installed/${TRIPLET}/tools/llvm/clang"
165-
170+
- name: 'Rellic test'
171+
shell: 'bash'
172+
if: ${{ matrix.llvm == 'llvm-14' && matrix.target_arch == 'x64' }}
173+
run: |
174+
# Test only should run when we're not cross compiling
175+
cd rellic/build
176+
../scripts/roundtrip.py ./tools/rellic-decomp ../tests/tools/decomp "${VCPKG_ROOT}/installed/${TARGET_TRIPLET}/tools/llvm/clang"
166177
- name: 'Remill build'
167178
shell: 'bash'
168-
if: ${{ matrix.llvm == 'llvm-14' }}
179+
if: ${{ matrix.llvm == 'llvm-14' && matrix.target_arch == 'x64' }}
169180
run: |
170181
cd remill
171182
mkdir -p build && cd build
172183
cmake -G Ninja \
173184
-DCMAKE_VERBOSE_MAKEFILE=ON \
174185
-DVCPKG_ROOT="${VCPKG_ROOT}" \
186+
-DVCPKG_TARGET_TRIPLET=${TARGET_TRIPLET} \
187+
-DCMAKE_OSX_ARCHITECTURES=${{ matrix.target_arch == 'x64' && 'x86_64' || matrix.target_arch }} \
175188
-DCMAKE_INSTALL_PREFIX="$(pwd)/install" \
176189
..
177190
cmake --build .
178191
cmake --build . --target install
179192
cmake --build . --target test_dependencies
193+
- name: 'Remill test'
194+
shell: 'bash'
195+
if: ${{ matrix.llvm == 'llvm-14' && matrix.target_arch == 'x64' }}
196+
run: |
197+
# Only run test on x64
180198
# Sometimes fails on a flaky test
199+
cd remill/build
181200
env CTEST_OUTPUT_ON_FAILURE=1 cmake --build . --target test || true
182-
183201
- name: 'Anvill build'
184202
shell: 'bash'
185-
if: ${{ matrix.llvm == 'llvm-14' }}
203+
if: ${{ matrix.llvm == 'llvm-14' && matrix.target_arch == 'x64' }}
186204
run: |
187205
cd anvill
188206
mkdir -p build && cd build
189207
cmake -G Ninja \
190208
-DCMAKE_VERBOSE_MAKEFILE=ON \
191209
-DCMAKE_INSTALL_PREFIX="$(pwd)/install" \
192210
-DVCPKG_ROOT="${VCPKG_ROOT}" \
211+
-DVCPKG_TARGET_TRIPLET=${TARGET_TRIPLET} \
212+
-DCMAKE_OSX_ARCHITECTURES=${{ matrix.target_arch == 'x64' && 'x86_64' || matrix.target_arch }} \
193213
-DANVILL_ENABLE_INSTALL_TARGET=ON \
194214
-DANVILL_ENABLE_PYTHON3_LIBS=OFF \
195215
-Dremill_DIR="$(pwd)/../../remill/build/install/lib/cmake/remill" \
196216
..
197217
cmake --build .
198218
cmake --build . --target install
219+
- name: 'Anvil test'
220+
shell: 'bash'
221+
if: ${{ matrix.llvm == 'llvm-14' && matrix.target_arch == 'x64' }}
222+
run: |
223+
# Only run test on x64
224+
cd anvill/build
199225
./install/bin/anvill-decompile-json -spec ../bin/Decompile/tests/specs/ret0.json -bc_out ./ret0.bc -ir_out ret0.ir
200-
201226
- name: Cache cleanup and reporting
202227
shell: 'bash'
203228
run: |

build_dependencies.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ function die {
1212

1313
function Help
1414
{
15-
echo "Usage: ./build_dependencies.sh [--release] [--asan] [--upgrade-ports] [--export-dir DIR] [...]"
15+
echo "Usage: ./build_dependencies.sh [--release] [--target-arch ARCH] [--asan] [--upgrade-ports] [--export-dir DIR] [...]"
1616
echo ""
1717
echo "Options:"
1818
echo " --release"
1919
echo " Build only release versions with triplet as detected in"
2020
echo " this script"
21+
echo " --target-arch <ARCH>"
22+
echo " Override target triplet architecture for cross compilation"
2123
echo " --asan"
2224
echo " Build with ASAN triplet as detected in this script"
2325
echo " --upgrade-ports"
@@ -57,6 +59,10 @@ while [[ $# -gt 0 ]] ; do
5759
RELEASE="true"
5860
msg "Building Release-only binaries"
5961
;;
62+
--target-arch)
63+
shift
64+
TARGET_ARCH=${1}
65+
;;
6066
--asan)
6167
ASAN="true"
6268
msg "Building ASAN binaries"
@@ -75,7 +81,7 @@ msg "Passing extra args to 'vcpkg install':"
7581
msg " " "${VCPKG_ARGS[@]}"
7682

7783
function die_if_not_installed {
78-
if ! type $1 &>/dev/null; then
84+
if ! type "$1" &>/dev/null; then
7985
die "Please install the package providing [${1}] command for your OS"
8086
fi
8187
}
@@ -118,7 +124,7 @@ export VCPKG_DISABLE_METRICS=1
118124

119125
msg "Building dependencies from source"
120126

121-
triplet=""
127+
target_triplet=""
122128
extra_vcpkg_args=()
123129
extra_cmake_usage_args=()
124130

@@ -147,20 +153,24 @@ else
147153
die "Could not detect OS. OS detection required for release-only builds."
148154
fi
149155

150-
triplet="${triplet_arch}-${triplet_os}"
156+
host_triplet="${triplet_arch}-${triplet_os}-rel"
157+
if [[ -v TARGET_ARCH ]]; then
158+
triplet_arch=${TARGET_ARCH}
159+
fi
160+
target_triplet="${triplet_arch}-${triplet_os}"
151161

152162
# Build-Type triplet
153163
if [[ ${RELEASE} == "true" ]]; then
154164
msg "Only building release versions"
155-
triplet="${triplet}-rel"
165+
target_triplet="${target_triplet}-rel"
156166
else
157167
msg "Building Release and Debug versions"
158168
fi
159169

160170
# ASAN triplet
161171
if [[ ${ASAN} == "true" ]]; then
162172
msg "Building with asan"
163-
triplet="${triplet}-asan"
173+
target_triplet="${target_triplet}-asan"
164174
fi
165175

166176
repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -171,9 +181,9 @@ if [[ -z ${EXPORT_DIR} ]]; then
171181
EXPORT_DIR="${vcpkg_dir}"
172182
fi
173183

174-
extra_vcpkg_args+=("--triplet=${triplet}" "--host-triplet=${triplet}" "--x-install-root=${EXPORT_DIR}/installed")
184+
extra_vcpkg_args+=("--triplet=${target_triplet}" "--host-triplet=${host_triplet}" "--x-install-root=${EXPORT_DIR}/installed")
175185

176-
extra_cmake_usage_args+=("-DVCPKG_TARGET_TRIPLET=${triplet}" "-DVCPKG_HOST_TRIPLET=${triplet}")
186+
extra_cmake_usage_args+=("-DVCPKG_TARGET_TRIPLET=${target_triplet}" "-DVCPKG_HOST_TRIPLET=${host_triplet}")
177187

178188
repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
179189
vcpkg_info_file="${repo_dir}/vcpkg_info.txt"

dependencies.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ gtest
55
gflags
66
protobuf
77
abseil
8-
grpc[absl-sync,codegen]
8+
grpc[codegen]
99
flatbuffers
1010
roaring
1111
rocksdb[zstd]

ports/llvm-15/portfile.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ list(APPEND FEATURE_OPTIONS
9696
# Force enable or disable external libraries
9797
set(llvm_external_libraries
9898
zlib
99+
zstd
99100
libxml2
100101
)
101102
foreach(external_library IN LISTS llvm_external_libraries)

ports/llvm-15/vcpkg.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "llvm-15",
33
"version": "15.0.1",
4+
"port-version": 1,
45
"description": "The LLVM Compiler Infrastructure.",
56
"homepage": "https://llvm.org",
67
"license": "Apache-2.0",
@@ -72,7 +73,8 @@
7273
"enable-eh",
7374
"enable-threads",
7475
"enable-z3",
75-
"enable-zlib"
76+
"enable-zlib",
77+
"enable-zstd"
7678
]
7779
}
7880
]
@@ -191,6 +193,12 @@
191193
"zlib"
192194
]
193195
},
196+
"enable-zstd": {
197+
"description": "Build with ZSTD.",
198+
"dependencies": [
199+
"zstd"
200+
]
201+
},
194202
"enable-z3": {
195203
"description": "Compile with Z3 SMT solver support for Clang static analyzer.",
196204
"dependencies": [

triplets/arm64-osx-rel.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(VCPKG_TARGET_ARCHITECTURE arm64)
2+
set(VCPKG_CRT_LINKAGE dynamic)
3+
set(VCPKG_LIBRARY_LINKAGE static)
4+
set(VCPKG_BUILD_TYPE release)
5+
6+
set(VCPKG_CMAKE_SYSTEM_NAME Darwin)
7+
set(VCPKG_OSX_ARCHITECTURES arm64)

0 commit comments

Comments
 (0)