-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configure cross-compilation for Apple Silicon #6360
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,7 +234,7 @@ jobs: | |
CCOMPILER: gcc-7 | ||
CXXCOMPILER: g++-7 | ||
|
||
- name: conan-osx-release-node-12 | ||
- name: conan-macos-x64-release-node-12 | ||
build_node_package: true | ||
continue-on-error: false | ||
node: 12 | ||
|
@@ -247,7 +247,7 @@ jobs: | |
ENABLE_ASSERTIONS: ON | ||
ENABLE_CONAN: ON | ||
|
||
- name: conan-osx-release-node-14 | ||
- name: conan-macos-x64-release-node-14 | ||
build_node_package: true | ||
continue-on-error: false | ||
node: 14 | ||
|
@@ -260,7 +260,7 @@ jobs: | |
ENABLE_ASSERTIONS: ON | ||
ENABLE_CONAN: ON | ||
|
||
- name: conan-osx-release-node-16 | ||
- name: conan-macos-x64-release-node-16 | ||
build_node_package: true | ||
continue-on-error: false | ||
node: 16 | ||
|
@@ -273,6 +273,20 @@ jobs: | |
ENABLE_ASSERTIONS: ON | ||
ENABLE_CONAN: ON | ||
|
||
- name: conan-macos-arm64-release-node-16 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added it for only Node 16 & Node-latest(i.e. Node 18), not sure if we actually need it for older versions, but it is easy to add if needed. |
||
build_node_package: true | ||
continue-on-error: false | ||
node: 16 | ||
runs-on: macos-11 | ||
BUILD_TOOLS: ON | ||
BUILD_TYPE: Release | ||
CCOMPILER: clang | ||
CXXCOMPILER: clang++ | ||
CUCUMBER_TIMEOUT: 60000 | ||
ENABLE_ASSERTIONS: ON | ||
ENABLE_CONAN: ON | ||
ENABLE_APPLE_SILICON: ON | ||
|
||
- name: gcc-7-release-shared | ||
continue-on-error: false | ||
node: 12 | ||
|
@@ -356,7 +370,19 @@ jobs: | |
ENABLE_CONAN: ON | ||
NODE_PACKAGE_TESTS_ONLY: ON | ||
|
||
- name: conan-osx-release-node-latest | ||
- name: conan-macos-x64-release-node-latest | ||
build_node_package: true | ||
continue-on-error: true | ||
node: latest | ||
runs-on: macos-11 | ||
BUILD_TYPE: Release | ||
CCOMPILER: clang | ||
CXXCOMPILER: clang++ | ||
CUCUMBER_TIMEOUT: 60000 | ||
ENABLE_ASSERTIONS: ON | ||
ENABLE_CONAN: ON | ||
|
||
- name: conan-macos-arm64-release-node-latest | ||
build_node_package: true | ||
continue-on-error: true | ||
node: latest | ||
|
@@ -367,6 +393,7 @@ jobs: | |
CUCUMBER_TIMEOUT: 60000 | ||
ENABLE_ASSERTIONS: ON | ||
ENABLE_CONAN: ON | ||
ENABLE_APPLE_SILICON: ON | ||
|
||
- name: node-latest-conan-linux-release | ||
build_node_package: true | ||
|
@@ -392,7 +419,7 @@ jobs: | |
ENABLE_CONAN: ON | ||
NODE_PACKAGE_TESTS_ONLY: ON | ||
|
||
- name: conan-osx-release-node-lts | ||
- name: conan-macos-x64-release-node-lts | ||
build_node_package: true | ||
continue-on-error: true | ||
node: "lts/*" | ||
|
@@ -403,6 +430,19 @@ jobs: | |
CUCUMBER_TIMEOUT: 60000 | ||
ENABLE_ASSERTIONS: ON | ||
ENABLE_CONAN: ON | ||
|
||
- name: conan-macos-arm64-release-node-lts | ||
build_node_package: true | ||
continue-on-error: true | ||
node: "lts/*" | ||
runs-on: macos-11 | ||
BUILD_TYPE: Release | ||
CCOMPILER: clang | ||
CXXCOMPILER: clang++ | ||
CUCUMBER_TIMEOUT: 60000 | ||
ENABLE_ASSERTIONS: ON | ||
ENABLE_CONAN: ON | ||
ENABLE_APPLE_SILICON: ON | ||
|
||
- name: node-lts-conan-linux-release | ||
build_node_package: true | ||
|
@@ -447,6 +487,7 @@ jobs: | |
ENABLE_CONAN: ${{ matrix.ENABLE_CONAN }} | ||
ENABLE_SANITIZER: ${{ matrix.ENABLE_SANITIZER }} | ||
NODE_PACKAGE_TESTS_ONLY: ${{ matrix.NODE_PACKAGE_TESTS_ONLY }} | ||
ENABLE_APPLE_SILICON: ${{ matrix.ENABLE_APPLE_SILICON }} | ||
TARGET_ARCH: ${{ matrix.TARGET_ARCH }} | ||
OSRM_CONNECTION_RETRIES: ${{ matrix.OSRM_CONNECTION_RETRIES }} | ||
OSRM_CONNECTION_EXP_BACKOFF_COEF: ${{ matrix.OSRM_CONNECTION_EXP_BACKOFF_COEF }} | ||
|
@@ -475,9 +516,9 @@ jobs: | |
uses: actions/cache@v2 | ||
with: | ||
path: ~/.conan | ||
key: v4-conan-${{ matrix.name }}-${{ github.sha }} | ||
key: v6-conan-${{ matrix.name }}-${{ github.sha }} | ||
restore-keys: | | ||
v4-conan-${{ matrix.name }}- | ||
v6-conan-${{ matrix.name }}- | ||
- name: Enable test cache | ||
uses: actions/cache@v2 | ||
with: | ||
|
@@ -583,6 +624,16 @@ jobs: | |
echo "Using ${JOBS} jobs" | ||
pushd ${OSRM_BUILD_DIR} | ||
|
||
# handle Apple Silicon cross compilation | ||
if [[ "${ENABLE_APPLE_SILICON}" == "ON" ]]; then | ||
ARCH=arm64 | ||
TARGET="${ARCH}-apple-darwin" | ||
CFLAGS="$CFLAGS --target=$TARGET" | ||
CXXFLAGS="$CXXFLAGS --target=$TARGET" | ||
APPLE_SILICON_FLAGS=(-DCMAKE_C_COMPILER_TARGET="$TARGET" -DCMAKE_CXX_COMPILER_TARGET="$TARGET" -DCMAKE_SYSTEM_PROCESSOR="${ARCH}" -DCMAKE_SYSTEM_NAME="Darwin" -DCMAKE_C_FLAGS="$CFLAGS" -DCMAKE_CXX_FLAGS="$CXXFLAGS") | ||
else | ||
APPLE_SILICON_FLAGS=() | ||
fi | ||
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ | ||
-DENABLE_CONAN=${ENABLE_CONAN:-OFF} \ | ||
-DENABLE_ASSERTIONS=${ENABLE_ASSERTIONS:-OFF} \ | ||
|
@@ -594,10 +645,11 @@ jobs: | |
-DBUILD_TOOLS=${BUILD_TOOLS:-OFF} \ | ||
-DENABLE_CCACHE=ON \ | ||
-DCMAKE_INSTALL_PREFIX=${OSRM_INSTALL_DIR} \ | ||
-DENABLE_GLIBC_WORKAROUND=${ENABLE_GLIBC_WORKAROUND:-OFF} | ||
-DENABLE_GLIBC_WORKAROUND=${ENABLE_GLIBC_WORKAROUND:-OFF} \ | ||
"${APPLE_SILICON_FLAGS[@]}" | ||
make --jobs=${JOBS} | ||
|
||
if [[ "${NODE_PACKAGE_TESTS_ONLY}" != "ON" ]]; then | ||
if [[ "${NODE_PACKAGE_TESTS_ONLY}" != "ON" && "${ENABLE_APPLE_SILICON}" != "ON" ]]; then | ||
make tests --jobs=${JOBS} | ||
make benchmarks --jobs=${JOBS} | ||
ccache -s | ||
|
@@ -609,15 +661,15 @@ jobs: | |
fi | ||
popd | ||
- name: Build example | ||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY != 'ON' }} | ||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY != 'ON' && matrix.ENABLE_APPLE_SILICON != 'ON' }} | ||
run: | | ||
mkdir example/build && pushd example/build | ||
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} | ||
make --jobs=${JOBS} | ||
popd | ||
|
||
- name: Run all tests | ||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY != 'ON' }} | ||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY != 'ON' && matrix.ENABLE_APPLE_SILICON != 'ON' }} | ||
run: | | ||
make -C test/data benchmark | ||
|
||
|
@@ -634,7 +686,7 @@ jobs: | |
popd | ||
npm test | ||
- name: Run Node package tests only | ||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' }} | ||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' && matrix.ENABLE_APPLE_SILICON != 'ON' }} | ||
run: | | ||
npm run nodejs-tests | ||
- name: Upload test logs | ||
|
@@ -659,9 +711,17 @@ jobs: | |
name: codecov-osrm-backend | ||
fail_ci_if_error: true | ||
verbose: true | ||
|
||
- name: Check Apple Silicon binary | ||
if: ${{ matrix.ENABLE_APPLE_SILICON == 'ON' }} | ||
run: | | ||
ARCH=$(file ./lib/binding/node_osrm.node | awk '{printf $NF}') | ||
if [[ "$ARCH" != "arm64" ]]; then | ||
file ./lib/binding/node_osrm.node | ||
>&2 echo "Wrong architecture!" | ||
exit 1 | ||
fi | ||
- name: Build Node package | ||
if: ${{ matrix.build_node_package && env.PUBLISH == 'On' }} | ||
if: ${{ matrix.build_node_package }} | ||
run: ./scripts/ci/node_package.sh | ||
- name: Publish Node package | ||
if: ${{ matrix.build_node_package && env.PUBLISH == 'On' }} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,15 @@ if (POLICY CMP0074) | |
endif() | ||
project(OSRM C CXX) | ||
|
||
# add @loader_path/$ORIGIN to rpath to make binaries relocatable | ||
if (APPLE) | ||
set(CMAKE_BUILD_RPATH "@loader_path") | ||
else() | ||
set(CMAKE_BUILD_RPATH "\$ORIGIN") | ||
# https://stackoverflow.com/questions/6324131/rpath-origin-not-having-desired-effect | ||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin") | ||
endif() | ||
|
||
include(JSONParser) | ||
file(READ "package.json" packagejsonraw) | ||
sbeParseJson(packagejson packagejsonraw) | ||
|
@@ -185,7 +194,7 @@ if(ENABLE_GOLD_LINKER) | |
execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) | ||
if("${LD_VERSION}" MATCHES "GNU gold") | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold -Wl,--disable-new-dtags") | ||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold -Wl,--disable-new-dtags") | ||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold -Wl,--disable-new-dtags") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks as just "copy-paste" mistake(and a reason why I had |
||
set(OSRM_LDFLAGS "${OSRM_LDFLAGS} -fuse-ld=gold -Wl,--disable-new-dtags") | ||
message(STATUS "Using GNU gold as linker.") | ||
|
||
|
@@ -489,11 +498,15 @@ if(ENABLE_CONAN) | |
NO_OUTPUT_DIRS | ||
OPTIONS boost:filesystem_version=3 # https://stackoverflow.com/questions/73392648/error-with-boost-filesystem-version-in-cmake | ||
onetbb:shared=${TBB_SHARED} | ||
boost:without_stacktrace=True # Apple Silicon cross-compilation fails without it | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not use it anyway. |
||
BUILD missing | ||
) | ||
# explicitly say Conan to use x86 dependencies if build for x86 platforms (https://github.com/conan-io/cmake-conan/issues/141) | ||
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) | ||
conan_cmake_run("${CONAN_ARGS};ARCH;x86") | ||
# cross-compilation for Apple Silicon | ||
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") | ||
conan_cmake_run("${CONAN_ARGS};ARCH;armv8") | ||
else() | ||
conan_cmake_run("${CONAN_ARGS}") | ||
endif() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,31 +7,31 @@ echo "node version is:" | |
which node | ||
node -v | ||
|
||
if [[ ${PUBLISH} == 'On' ]]; then | ||
echo "PUBLISH is set to '${PUBLISH}', publishing!" | ||
NPM_FLAGS='' | ||
if [[ ${BUILD_TYPE} == "Debug" ]]; then | ||
NPM_FLAGS='--debug' | ||
fi | ||
NPM_FLAGS='' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why don't we run it on every CI. We have a couple of useful checks here and it turned out that one of them was red, so worth running it always probably. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I mean this check on Linux that we have proper ORIGIN flags a couple of lines below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, makes sense. |
||
if [[ ${BUILD_TYPE} == "Debug" ]]; then | ||
NPM_FLAGS='--debug' | ||
fi | ||
|
||
# append --target_arch in order to handle cross-compilation for Apple Silicon | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only actual change in this file. |
||
if [[ "$ENABLE_APPLE_SILICON" == "ON" ]]; then | ||
NPM_FLAGS="${NPM_FLAGS} --target_arch=arm64" | ||
fi | ||
|
||
echo "dumping binary meta..." | ||
./node_modules/.bin/node-pre-gyp reveal $NPM_FLAGS | ||
echo "dumping binary meta..." | ||
./node_modules/.bin/node-pre-gyp reveal $NPM_FLAGS | ||
|
||
# enforce that binary has proper ORIGIN flags so that | ||
# it can portably find libtbb.so in the same directory | ||
if [[ $(uname -s) == 'Linux' ]]; then | ||
readelf -d ./lib/binding/node_osrm.node > readelf-output.txt | ||
if grep -q 'Flags: ORIGIN' readelf-output.txt; then | ||
echo "Found ORIGIN flag in readelf output" | ||
cat readelf-output.txt | ||
else | ||
echo "*** Error: Could not found ORIGIN flag in readelf output" | ||
cat readelf-output.txt | ||
exit 1 | ||
fi | ||
# enforce that binary has proper ORIGIN flags so that | ||
# it can portably find libtbb.so in the same directory | ||
if [[ $(uname -s) == 'Linux' ]]; then | ||
readelf -d ./lib/binding/node_osrm.node > readelf-output.txt | ||
if grep -q 'Flags: ORIGIN' readelf-output.txt; then | ||
echo "Found ORIGIN flag in readelf output" | ||
cat readelf-output.txt | ||
else | ||
echo "*** Error: Could not found ORIGIN flag in readelf output" | ||
cat readelf-output.txt | ||
exit 1 | ||
fi | ||
|
||
./node_modules/.bin/node-pre-gyp package testpackage $NPM_FLAGS | ||
else | ||
echo "PUBLISH is set to '${PUBLISH}', skipping." | ||
fi | ||
|
||
./node_modules/.bin/node-pre-gyp package testpackage $NPM_FLAGS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How I have tested this: since we do not have Apple Silicon based CI we cannot run tests there, so I just downloaded binaries from CI artefacts and ran tests locally putting these binaries to ./lib/binding folder before it.