From 05f509662476fc1b0f2ac8ec259e06679e665093 Mon Sep 17 00:00:00 2001 From: Alex Andres Date: Sun, 27 Sep 2026 01:48:49 +0200 Subject: [PATCH] build: cross compile the macOS x86_64 target natively on Apple Silicon The Intel macOS build already ran on an Apple Silicon runner, but all of it under Rosetta: an x64 JDK, and every Maven call behind arch -x86_64, so CMake, clang, gn, ninja and FFmpeg's configure and make were all emulated. Maven now runs natively and cross compiles: - the root pom gains a macos-cross-x86_64 profile that sets the macos-x86_64 classifier, declared after macos-aarch64, which the host still activates - the media module takes webrtc-jni's x86_64-macos-cross.cmake toolchain, so FFmpeg is configured as a cross build; Apple's strip reads any Mach-O, so its output stays stripped - the CI actions build with an arm64 JDK and run only the tests on an x64 one, which is what loading the Intel natives needs --- .github/actions/build-macos-x86_64/action.yml | 22 +++++++++++++++---- .../actions/release-macos-x86_64/action.yml | 18 ++++++++++++--- pom.xml | 10 +++++++++ webrtc-java-media/pom.xml | 13 ++++++----- .../cpp/dependencies/ffmpeg/CMakeLists.txt | 7 ++++-- 5 files changed, 56 insertions(+), 14 deletions(-) diff --git a/.github/actions/build-macos-x86_64/action.yml b/.github/actions/build-macos-x86_64/action.yml index 81f1a44e..816ac11f 100644 --- a/.github/actions/build-macos-x86_64/action.yml +++ b/.github/actions/build-macos-x86_64/action.yml @@ -52,22 +52,36 @@ runs: key: maven-${{ inputs.platform-name }}-${{ hashFiles('**/pom.xml') }} restore-keys: maven-${{ inputs.platform-name }}- - - name: Set up JDK + # The runner is Apple Silicon. The build runs natively and cross compiles + # for Intel; only the tests need an Intel JVM, to load what was built, and + # that one runs under Rosetta. + - id: jdk-x64 + name: Set up JDK (x64, for the tests) uses: actions/setup-java@v5 with: architecture: 'x64' java-version: ${{ inputs.java-version }} distribution: 'temurin' + overwrite-settings: false + + # Set up last, so that it is the JAVA_HOME the build runs with and the one + # whose settings.xml carries the deploy credentials. + - name: Set up JDK (arm64, for the build) + uses: actions/setup-java@v5 + with: + architecture: 'aarch64' + java-version: ${{ inputs.java-version }} + distribution: 'temurin' server-id: central server-username: MAVEN_USERNAME server-password: MAVEN_TOKEN - name: Build - run: arch -x86_64 mvn package -DskipTests -Pmacos-cross-x86_64 + run: mvn package -DskipTests -Pmacos-cross-x86_64 shell: bash - name: Test - run: arch -x86_64 mvn -B jar:jar surefire:test -Pmacos-cross-x86_64 + run: JAVA_HOME="${{ steps.jdk-x64.outputs.path }}" mvn -B jar:jar surefire:test -Pmacos-cross-x86_64 shell: bash - name: Deploy @@ -75,5 +89,5 @@ runs: env: MAVEN_USERNAME: ${{ inputs.maven-username }} MAVEN_TOKEN: ${{ inputs.maven-password }} - run: arch -x86_64 mvn deploy -DskipTests -Pmacos-cross-x86_64 + run: mvn deploy -DskipTests -Pmacos-cross-x86_64 shell: bash diff --git a/.github/actions/release-macos-x86_64/action.yml b/.github/actions/release-macos-x86_64/action.yml index 9e77fbfd..25244cf4 100644 --- a/.github/actions/release-macos-x86_64/action.yml +++ b/.github/actions/release-macos-x86_64/action.yml @@ -44,19 +44,31 @@ runs: key: maven-${{ inputs.platform-name }}-${{ hashFiles('**/pom.xml') }} restore-keys: maven-${{ inputs.platform-name }}- - - name: Set up JDK ${{ inputs.java-version }} + # The runner is Apple Silicon. The build runs natively and cross compiles + # for Intel; only the tests need an Intel JVM, to load what was built, and + # that one runs under Rosetta. + - id: jdk-x64 + name: Set up JDK ${{ inputs.java-version }} (x64, for the tests) uses: actions/setup-java@v5 with: architecture: 'x64' java-version: ${{ inputs.java-version }} distribution: 'temurin' + # Set up last, so that it is the JAVA_HOME the build runs with. + - name: Set up JDK ${{ inputs.java-version }} (arm64, for the build) + uses: actions/setup-java@v5 + with: + architecture: 'aarch64' + java-version: ${{ inputs.java-version }} + distribution: 'temurin' + - name: Build - run: arch -x86_64 mvn package -DskipTests -Pmacos-cross-x86_64 + run: mvn package -DskipTests -Pmacos-cross-x86_64 shell: bash - name: Test - run: arch -x86_64 mvn -B jar:jar surefire:test -Pmacos-cross-x86_64 + run: JAVA_HOME="${{ steps.jdk-x64.outputs.path }}" mvn -B jar:jar surefire:test -Pmacos-cross-x86_64 shell: bash # Maven Central publishes a version as one atomic bundle, so this job must not diff --git a/pom.xml b/pom.xml index 90d3a69d..29978171 100644 --- a/pom.xml +++ b/pom.xml @@ -355,6 +355,16 @@ webrtc.macos.aarch64 + + + macos-cross-x86_64 + + macos-x86_64 + webrtc.macos.x86_64 + + diff --git a/webrtc-java-media/pom.xml b/webrtc-java-media/pom.xml index d2ba8c2c..4e33fd74 100644 --- a/webrtc-java-media/pom.xml +++ b/webrtc-java-media/pom.xml @@ -42,8 +42,8 @@ same glibc floor. On Linux that also means compiling with -nostdinc++ and taking the C++ standard library from where webrtc-jni takes it, which is what webrtc.install.dir is for - below. macOS builds for the architecture Maven runs as and needs - no file. --> + below. A native macOS build needs no file; the Intel build made on + Apple Silicon takes webrtc-jni's cross one. --> ${project.basedir}/../webrtc-jni/src/main/cpp/toolchain + + macos-cross-x86_64 + + ${jni.toolchain.dir}/x86_64-macos-cross.cmake +