Skip to content

Commit f642ea8

Browse files
committed
macos build
1 parent ef3413d commit f642ea8

11 files changed

Lines changed: 197 additions & 40 deletions

File tree

.github/workflows/gradle.yml

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,94 @@ on:
1111
workflow_dispatch:
1212

1313
jobs:
14-
build:
14+
build-macos:
15+
runs-on: macos-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
submodules: recursive
20+
21+
- name: Set up JDK
22+
uses: actions/setup-java@v4
23+
with:
24+
java-version: '21'
25+
distribution: 'temurin'
26+
cache: gradle
27+
28+
- name: Install dependencies
29+
run: |
30+
brew update
31+
brew install cmake ninja pkg-config openssl conan
32+
conan --version
33+
34+
- name: Setup Gradle
35+
uses: gradle/actions/setup-gradle@v4
36+
37+
- name: Build macOS Native Libraries
38+
run: |
39+
export VERSION=""
40+
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
41+
export VERSION="-Pversion=${GITHUB_REF#refs/tags/}"
42+
fi
43+
./gradlew packageNativeForDarwinArm64 packageNativeForDarwinX8664 --no-daemon --no-parallel $VERSION
44+
45+
- name: Upload macOS artifacts
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: macos-prebuilt
49+
path: build/libs/libdatachannel-java-*-darwin-*.jar
50+
retention-days: 1
51+
52+
build-publish:
1553
runs-on: ubuntu-latest
54+
needs: build-macos
1655
steps:
1756
- uses: actions/checkout@v4
1857
with:
1958
submodules: recursive
59+
2060
- name: Set up JDK
2161
uses: actions/setup-java@v4
2262
with:
2363
java-version: '11'
2464
distribution: 'temurin'
2565
cache: gradle
66+
2667
- name: Setup Gradle
2768
uses: gradle/actions/setup-gradle@v4
28-
- name: Build
69+
70+
- name: Download macOS prebuilt libraries
71+
uses: actions/download-artifact@v4
72+
with:
73+
name: macos-prebuilt
74+
path: prebuilt
75+
76+
- name: List prebuilt libraries
77+
run: |
78+
mkdir -p prebuilt
79+
ls -la prebuilt
80+
81+
- name: Build and Publish
2982
if: github.event_name != 'push' && github.event_name != 'release'
3083
run: |
31-
./gradlew --no-configuration-cache --no-parallel assemble
32-
- name: Publish
84+
export VERSION=""
85+
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
86+
export VERSION="-Pversion=${GITHUB_REF#refs/tags/}"
87+
fi
88+
./gradlew --no-configuration-cache --no-parallel assemble
89+
90+
- name: Publish to Repository
3391
if: github.event_name == 'push' || github.event_name == 'release'
3492
run: |
3593
export VERSION=""
3694
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
3795
export VERSION="-Pversion=${GITHUB_REF#refs/tags/}"
3896
fi
39-
./gradlew --no-configuration-cache --no-parallel $VERSION -Pgpr.user=${{ github.actor }} -Pgpr.key=${{ secrets.GITHUB_TOKEN }} -Pgpr.owner=${{ github.repository_owner }} publish
40-
97+
./gradlew --no-configuration-cache --no-daemon --no-parallel $VERSION -Pgpr.user=${{ github.actor }} -Pgpr.key=${{ secrets.GITHUB_TOKEN }} -Pgpr.owner=${{ github.repository_owner }} publish
98+
99+
- name: Upload distribution artifacts
100+
uses: actions/upload-artifact@v4
101+
with:
102+
name: dist
103+
path: dist
104+
retention-days: 7

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ out/
1010
*.log
1111
ndk
1212
dist
13-
bin
13+
bin
14+
prebuilt

arch-detect/build.gradle.kts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,38 @@ dependencies {
1616
"configuration" to "archDetectConfiguration"
1717
)))
1818
}
19-
2019
tasks.jar.configure {
2120
dependsOn(nativeLibs)
22-
for (artifact in nativeLibs.get().resolvedConfiguration.resolvedArtifacts) {
23-
val classifier = artifact.classifier ?: continue
21+
val allArtifacts = mutableListOf<Pair<File, String>>()
22+
23+
// Add resolved artifacts
24+
nativeLibs.get().resolvedConfiguration.resolvedArtifacts.forEach { artifact ->
25+
val classifier = artifact.classifier
26+
if (classifier != null && !classifier.startsWith("android-")) {
27+
allArtifacts.add(Pair(artifact.file, classifier))
28+
}
29+
}
30+
31+
// Add prebuilt libraries
32+
val prebuiltArtifacts = rootProject.extra["prebuiltArtifacts"] as? List<Pair<File, String>> ?: emptyList()
33+
prebuiltArtifacts.forEach { (file, classifier) ->
2434
if (!classifier.startsWith("android-")) {
25-
val classifier = artifact.classifier ?: continue
26-
from(zipTree(artifact.file)) {
27-
include("native/*.so")
28-
include("native/*.dll")
29-
into(classifier)
30-
}
35+
allArtifacts.add(file to classifier)
36+
logger.lifecycle("Found prebuilt library: ${file.name} with classifier: $classifier")
3137
}
3238
}
39+
40+
// Process all artifacts
41+
allArtifacts.forEach { (file, classifier) ->
42+
from(zipTree(file)) {
43+
include("native/*.so")
44+
include("native/*.dll")
45+
include("native/*.dylib")
46+
into(classifier)
47+
}
48+
logger.lifecycle("Added library to arch-detect JAR: ${file.name} with classifier: $classifier")
49+
}
3350
}
34-
3551
// val androidAar by tasks.registering(Zip::class) {
3652
// group = "build"
3753
// archiveBaseName.set(project.name+"-android")

build.gradle.kts

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,45 @@ val buildReleaseBinaries = project.findProperty("libdatachannel.build-release-bi
8585
?.toBooleanStrictOrNull()
8686
?: !project.version.toString().endsWith("-SNAPSHOT")
8787

88+
89+
90+
// Detect prebuilt libraries
91+
project.extra["prebuiltArtifacts"] = mutableListOf<Pair<File, String>>()
92+
val prebuiltLibsDir = project.layout.projectDirectory.dir("prebuilt")
93+
if (prebuiltLibsDir.asFile.exists()) {
94+
prebuiltLibsDir.asFile.listFiles()?.filter {
95+
it.isFile && it.name.endsWith(".jar")
96+
}?.forEach { jarFile ->
97+
// Extract version and classifier from filename
98+
val filenameRegex = """libdatachannel-java-(.*)-([^-]+)-([^-]+)\.jar""".toRegex();
99+
val matchResult = filenameRegex.find(jarFile.name)
100+
if (matchResult != null) {
101+
val (version, os, arch) = matchResult.destructured
102+
val classifier = "${os}-${arch}"
103+
104+
if (version == project.version.toString()) {
105+
// Add to publications
106+
publishing.publications.withType<MavenPublication>().configureEach {
107+
artifact(jarFile) {
108+
this.classifier = classifier
109+
}
110+
}
111+
112+
// Add to the prebuilt artifacts list in project.extra
113+
val prebuiltArtifacts = project.extra["prebuiltArtifacts"] as MutableList<Pair<File, String>>
114+
prebuiltArtifacts.add(jarFile to classifier)
115+
116+
logger.lifecycle("Added prebuilt library: ${jarFile.name} with classifier: $classifier")
117+
} else {
118+
logger.warn("Skipping prebuilt library ${jarFile.name} as its version $version does not match the project version ${project.version}.")
119+
}
120+
} else {
121+
logger.warn("Skipping prebuilt library ${jarFile.name} as it does not match the expected naming convention.")
122+
}
123+
}
124+
}
125+
126+
88127
fun DockcrossRunTask.baseConfigure(outputTo: Directory, target: BuildTarget) {
89128
group = nativeGroup
90129

@@ -138,6 +177,7 @@ fun Jar.baseConfigure(compileTask: TaskProvider<DockcrossRunTask>, buildOutputDi
138177
from(buildOutputDir) {
139178
include("native/libdatachannel-java.so")
140179
include("native/libdatachannel-java.dll")
180+
include("native/libdatachannel-java.dylib")
141181
}
142182
}
143183

@@ -161,28 +201,40 @@ data class BuildTarget(
161201
val args: List<String> = emptyList(),
162202
)
163203

164-
val targets = listOf(
165-
BuildTarget(image = "linux-x64", classifier = "x86_64"),
166-
BuildTarget(image = "linux-x86", classifier = "x86_32"),
167-
BuildTarget(image = "linux-arm64", classifier = "aarch64"),
168-
BuildTarget(image = "windows-static-x64", classifier = "windows-x86_64"),
204+
val isMacOS = org.gradle.internal.os.OperatingSystem.current().isMacOsX()
205+
val targets = buildList {
206+
// Always add these targets
207+
add(BuildTarget(image = "linux-x64", classifier = "x86_64"))
208+
add(BuildTarget(image = "linux-x86", classifier = "x86_32"))
209+
add(BuildTarget(image = "linux-arm64", classifier = "aarch64"))
210+
add(BuildTarget(image = "windows-static-x64", classifier = "windows-x86_64"))
169211
// BuildTarget(image = "windows-static-x86", classifier = "windows-x86_32"),
212+
213+
// Add macOS targets only when running on macOS
214+
if (isMacOS) {
215+
add(BuildTarget(image = "host", classifier = "darwin-x86_64",
216+
args = listOf("-DCMAKE_OSX_ARCHITECTURES=x86_64", "-DCMAKE_POLICY_VERSION_MINIMUM=3.5")))
217+
add(BuildTarget(image = "host", classifier = "darwin-arm64",
218+
args = listOf("-DCMAKE_OSX_ARCHITECTURES=arm64", "-DCMAKE_POLICY_VERSION_MINIMUM=3.5")))
219+
}
220+
221+
// Android targets
222+
// add(BuildTarget(
223+
// image = "android-arm64",
224+
// classifier = "android-arm64-v8a",
225+
// args = listOf("-DANDROID_ABI=arm64-v8a", "-DANDROID_PLATFORM=android-21"),
226+
// ))
227+
// add(BuildTarget(
228+
// image = "android-x86_64",
229+
// classifier = "android-x86_64",
230+
// args = listOf("-DANDROID_ABI=x86_64", "-DANDROID_PLATFORM=android-21"),
231+
// ))
170232
// BuildTarget(
171233
// image = "android-arm",
172234
// classifier = "android-armeabi-v7a",
173235
// args = listOf("-DANDROID_ABI=armeabi-v7a", "-DANDROID_PLATFORM=android-21"),
174236
// ),
175-
BuildTarget(
176-
image = "android-arm64",
177-
classifier = "android-arm64-v8a",
178-
args = listOf("-DANDROID_ABI=arm64-v8a", "-DANDROID_PLATFORM=android-21"),
179-
),
180-
BuildTarget(
181-
image = "android-x86_64",
182-
classifier = "android-x86_64",
183-
args = listOf("-DANDROID_ABI=x86_64", "-DANDROID_PLATFORM=android-21"),
184-
),
185-
)
237+
}
186238

187239
val packageNativeAll by tasks.registering(DefaultTask::class) {
188240
group = nativeGroup
@@ -198,7 +250,10 @@ for (target in targets) {
198250
unsafeWritableMountSource = true
199251
containerName = "dockcross-${project.name}-${target.classifier}"
200252

201-
if (ci) {
253+
254+
if (target.image == "host" ){
255+
runner(NonContainerRunner)
256+
}else if (ci) {
202257
runner(DockerRunner())
203258
}
204259
}

jni/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ endif()
3131
add_link_options(-fvisibility=hidden)
3232
if(ANDROID)
3333
add_link_options(-z noexecstack -static-libgcc -static-libstdc++)
34+
elseif(APPLE)
35+
add_link_options(-dead_strip)
36+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
37+
set(CMAKE_INSTALL_RPATH "@loader_path")
38+
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
39+
set(CMAKE_MACOSX_RPATH ON)
3440
elseif(NOT WIN32)
3541
add_link_options(-z noexecstack)
3642
else()

jni/conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ class LibDataChannel(ConanFile):
77
generators = "CMakeDeps"
88

99
def configure(self):
10-
self.options["openssl"].shared = self.settings.os != "Windows" and self.settings.os != "Android"
10+
self.options["openssl"].shared = self.settings.os != "Windows" and self.settings.os != "Android" and self.settings.os != "Macos"

jni/src/callback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "callback.h"
22
#include "util.h"
33
#include "global_jvm.h"
4-
#include <malloc.h>
4+
#include <stdlib.h>
55

66
struct jvm_callback* allocate_callback(JNIEnv* env, jobject callback) {
77
struct jvm_callback* cb = malloc(sizeof(struct jvm_callback));

jni/src/native_channel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <jni.h>
22
#include <rtc/rtc.h>
33
#include <jni-java-to-c.h>
4-
#include <malloc.h>
4+
#include <stdlib.h>
55
#include "jni-c-to-java.h"
66
#include "util.h"
77
#include "callback.h"

jni/src/native_peer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <jni.h>
22
#include <rtc/rtc.h>
33
#include <jni-java-to-c.h>
4-
#include <malloc.h>
4+
#include <stdlib.h>
55
#include <jni-c-to-java.h>
66
#include "util.h"
77
#include "callback.h"

jni/src/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "util.h"
22
#include <jni-c-to-java.h>
3-
#include <malloc.h>
3+
#include <stdlib.h>
44
#include <errno.h>
55
#include <string.h>
66
#include <jni-java-to-c.h>

0 commit comments

Comments
 (0)