Skip to content

Commit

Permalink
setup darwin cross-compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
LandryNorris committed Aug 18, 2023
1 parent 2336ab5 commit 8ba0f25
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/librhsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ elseif(SYSTEM STREQUAL "LinuxX64")
elseif(SYSTEM STREQUAL "LinuxArm64")
add_compile_options("-target" "aarch64-pc-linux-gnu")
add_link_options("-target" "aarch64-pc-linux-gnu" "-fuse-ld=/usr/bin/aarch64-linux-gnu-ld")
elseif(SYSTEM STREQUAL "DarwinX64")
add_compile_options("-target" "x86_64-apple-darwin")
elseif(SYSTEM STREQUAL "DarwinArm64")
add_compile_options("-target" "aarch64-apple-darwin")
else()
message("Target platform is not defined")
endif()
Expand Down
12 changes: 12 additions & 0 deletions packages/librhsp/librhsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ if(CMAKE_CROSSCOMPILING)
src/arch/win/serial.c
)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
list(APPEND LIB_SOURCES
src/arch/mac/time.c
src/arch/mac/serial.c
)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
add_compile_options("-target" "x86_64-pc-linux-gnu")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
add_compile_options("-target" "aarch64-pc-linux-gnu")
else()
message(FATAL_ERROR "Unsupported architecture for Darwin cross-compilation:'${CMAKE_SYSTEM_PROCESSOR}'")
endif()
else()
message(FATAL_ERROR "Unsupported system for cross-compilation:'${CMAKE_SYSTEM_NAME}'")
endif()
Expand Down
4 changes: 2 additions & 2 deletions packages/librhsp/scripts/macos-cross-build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ fs.mkdirSync(path.join(prebuiltsFolder, "darwin-arm64"), { recursive: true })
let cmakeJsArgs = [ "compile", "--config", "Release", "--CDCMAKE_SYSTEM_NAME=Darwin", "--prefer-clang=true" ]

console.log("Prebuildifying")
await runCmakeJs([...cmakeJsArgs, "--CDCMAKE_SYSTEM_PROCESSOR=x86_64"], baseBuildPath + "js-darwinX64");
await runCmakeJs([...cmakeJsArgs, "--CDCMAKE_SYSTEM_PROCESSOR=arm64"], baseBuildPath + "js-darwinArm64");
await runCmakeJs([...cmakeJsArgs, "--CDCMAKE_SYSTEM_PROCESSOR=x86_64 --CDSYSTEM=DarwinX64"], baseBuildPath + "js-darwinX64");
await runCmakeJs([...cmakeJsArgs, "--CDCMAKE_SYSTEM_PROCESSOR=arm64 --CDSYSTEM=DarwinArm64"], baseBuildPath + "js-darwinArm64");

fs.copyFileSync(baseBuildPath + "js-darwinX64/rhsp.node", path.join(prebuiltsFolder, "darwin-x64/rhsp.node"))
fs.copyFileSync(baseBuildPath + "js-darwinArm64/rhsp.node", path.join(prebuiltsFolder, "darwin-arm64/rhsp.node"))
Expand Down

0 comments on commit 8ba0f25

Please sign in to comment.