Skip to content

Commit

Permalink
arrow: Fix cross-compiling errors on macos
Browse files Browse the repository at this point in the history
This fixes the issue with missing LZ4 symbols in the arm64
wheel first introduced in v3.1.1.

The crux of the issue is that Arrow was building lz4 (and zstd) in a
separate cmake build, and it does not specially pass on the
`CMAKE_OSX_ARCHITECTURES` flag that was set when perspective-server's
build script invokes cmake.

Arrow's build does forward on the value of CMAKE_TOOLCHAIN_FILE to its
external dependencies, if it's set, so this commit creates two minimal
toolchain files and uses them in the Mac build to set
`CMAKE_OSX_ARCHITECTURES` (and a couple other variables) correctly when
cross-compiling.

a good follow-up would be to see if we can enable Python tests on
arm64 using a macos-14 runner, which is available for public repos:
<https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories>

Signed-off-by: Tom Jakubowski <[email protected]>
  • Loading branch information
tomjakubowski committed Oct 22, 2024
1 parent 2db5679 commit 3ad6d2d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
24 changes: 24 additions & 0 deletions cmake/toolchains/darwin-arm64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
# ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
# ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
# ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
# ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
# ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
# ┃ Copyright (c) 2017, the Perspective Authors. ┃
# ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
# ┃ This file is part of the Perspective library, distributed under the terms ┃
# ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

# Minimal toolchain file to ensure that Arrow's bundled dependency builds use
# the correct architecture for Mac builds.

# (Arrow does not as of Oct 2024 pass on CMAKE_OSX_ARCHITECTURES to its
# dependencies if it is set, but does pass on a toolchain file)

set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "Target architecture for Mac builds")
# Arrow uses this to choose a `-march` flag
set(CMAKE_SYSTEM_PROCESSOR "arm64")
# Prevent cmake from overwriting CMAKE_SYSTEM_PROCESSOR
# https://github.com/apache/arrow/issues/44448#issuecomment-2418649378
set(CMAKE_SYSTEM_NAME "Darwin")
24 changes: 24 additions & 0 deletions cmake/toolchains/darwin-x86_64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
# ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
# ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
# ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
# ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
# ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
# ┃ Copyright (c) 2017, the Perspective Authors. ┃
# ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
# ┃ This file is part of the Perspective library, distributed under the terms ┃
# ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

# Minimal toolchain file to ensure that Arrow's bundled dependency builds use
# the correct architecture for Mac builds.

# (Arrow does not as of Oct 2024 pass on CMAKE_OSX_ARCHITECTURES to its
# dependencies if it is set, but does pass on a toolchain file)

set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Target architecture for Mac builds")
# Arrow uses this to choose a `-march` flag
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
# Prevent cmake from overwriting CMAKE_SYSTEM_PROCESSOR
# https://github.com/apache/arrow/issues/44448#issuecomment-2418649378
set(CMAKE_SYSTEM_NAME "Darwin")
22 changes: 18 additions & 4 deletions rust/perspective-server/build/psp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,24 @@ pub fn cmake_build() -> Result<Option<PathBuf>, std::io::Error> {
let profile = std::env::var("PROFILE").unwrap();
dst.always_configure(true);
dst.define("CMAKE_BUILD_TYPE", profile.as_str());
if std::env::var("PSP_ARCH").as_deref() == Ok("x86_64") {
dst.define("CMAKE_OSX_ARCHITECTURES", "x86_64");
} else if std::env::var("PSP_ARCH").as_deref() == Ok("arm64") {
dst.define("CMAKE_OSX_ARCHITECTURES", "arm64");

if cfg!(target_os = "macos") {
// Set CMAKE_OSX_ARCHITECTURES et al. for Mac builds. Arrow does not forward on
// CMAKE_OSX_ARCHITECTURES and but it does forward on a
// CMAKE_TOOLCHAIN_FILE. In Conda builds, the environment sets
// `CMAKE_ARGS` up with various toolchain arguments. This block may need
// to be patched out or adjusted for Conda.
let toolchain_file = match std::env::var("PSP_ARCH").as_deref() {
Ok("x86_64") => "./cmake/toolchains/darwin-x86_64.cmake",
Ok("aarch64") => "./cmake/toolchains/darwin-arm64.cmake",
arch @ Ok(_) | arch @ Err(_) => {
panic!("Unknown PSP_ARCH value: {:?}", arch)
},
};
dst.define(
"CMAKE_TOOLCHAIN_FILE",
std::fs::canonicalize(toolchain_file).expect("Failed to canonicalize toolchain file."),
);
}

if std::env::var("TARGET")
Expand Down

0 comments on commit 3ad6d2d

Please sign in to comment.