Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: Build NetworkTypeFinder JNI Bridge
name: Build Native Libraries

on:
push:
paths:
- 'composeApp/src/desktopMain/c/**'
- '.github/workflows/build-networktypefinder.yml'
- '.github/workflows/build_native_libraries.yml'
- 'composeApp/src/desktopMain/Makefile'
pull_request:
paths:
- 'composeApp/src/desktopMain/c/**'
- '.github/workflows/build-networktypefinder.yml'
- '.github/workflows/build_native_libraries.yml'
- 'composeApp/src/desktopMain/Makefile'

jobs:
Expand Down Expand Up @@ -44,11 +44,11 @@ jobs:
if: runner.os == 'Windows'
run: choco install llvm make

- name: Build NetworkTypeFinder
- name: Build Native Libraries
run: make all

- name: Upload built library
uses: actions/upload-artifact@v4
with:
name: networktypefinder-${{ matrix.os }}
path: composeApp/src/desktopMain/build/
path: composeApp/src/desktopMain/resources/
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ captures
.kotlin
Gemfile.lock
output
!composeApp/src/desktopMain/build/libnetworktypefinder.dylib
!composeApp/src/desktopMain/build/libnetworktypefinder.so
!composeApp/src/desktopMain/build/networktypefinder.dll
!composeApp/src/desktopMain/resources/macos/*.dylib
!composeApp/src/desktopMain/resources/linux/*.so
!composeApp/src/desktopMain/resources/windows/*.dll

/composeApp/src/desktopMain/frameworks/
87 changes: 69 additions & 18 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import com.android.build.api.variant.FilterConfiguration.FilterType.ABI
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
import java.time.LocalDate
import org.gradle.internal.os.OperatingSystem
import org.gradle.kotlin.dsl.java
import org.jetbrains.compose.ExperimentalComposeLibrary
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
Expand Down Expand Up @@ -217,8 +220,8 @@ android {
targetSdk = libs.versions.android.targetSdk
.get()
.toInt()
versionCode = 230 // Always increment by 10. See fdroid flavor below
versionName = "5.2.1"
versionCode = 200 // Always increment by 10. See fdroid flavor below
versionName = "5.0.0"
Comment on lines +223 to +224
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't want to merge this, just use if for tests.

resValue("string", "app_name", config.appName)
resValue("string", "ooni_run_enabled", config.supportsOoniRun.toString())
resValue(
Expand Down Expand Up @@ -407,30 +410,55 @@ compose.desktop {
packageVersion = android.defaultConfig.versionName
description =
"OONI Probe is a free and open source software designed to measure internet censorship and other forms of network interference."
copyright = "© 2024 OONI. All rights reserved."
copyright = "© ${LocalDate.now().year} OONI. All rights reserved."
vendor = "Open Observatory of Network Interference (OONI)"
// licenseFile.set(project.file("LICENSE.txt"))
licenseFile = rootProject.file("LICENSE")

modules("java.sql", "jdk.unsupported")

// Include native libraries
includeAllModules = true

val appResource = project.layout.projectDirectory.dir("src/desktopMain/resources/")
println(" Project directory: $appResource")
appResourcesRootDir.set(appResource)

macOS {
minimumSystemVersion = "12.0.0"
// Hide dock icon
bundleID = "org.ooni.probe"
infoPlist {
extraKeysRawXml = """
<key>LSUIElement</key>
<string>true</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>ooni</string>
<key>CFBundleURLSchemes</key>
<array>
<key>LSUIElement</key>
<string>true</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>ooni</string>
</array>
</dict>
</array>
<key>CFBundleURLSchemes</key>
<array>
<string>ooni</string>
</array>
</dict>
</array>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
<key>com.apple.security.cs.debugger</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.files.downloads.read-write</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
""".trimIndent()
}
jvmArgs("-Dapple.awt.enableTemplateImages=true") // tray template icon
Expand Down Expand Up @@ -498,17 +526,40 @@ tasks {
val makeLibrary by tasks.registering(Exec::class) {
workingDir = file("src/desktopMain")
commandLine = listOf("make", "all")
description = "Build native libraries (NetworkTypeFinder and UpdateBridge)"
doFirst {
println("🔨 Building native libraries...")
}
doLast {
println("✅ Native libraries built successfully")
}
}

val cleanLibrary by tasks.registering(Exec::class) {
workingDir = file("src/desktopMain")
commandLine = listOf("make", "clean")
description = "Clean native library build artifacts"
}

// Ensure native libraries are built before desktop compilation
tasks.named("compileKotlinDesktop").configure {
// dependsOn(makeLibrary)
}

tasks.withType<JavaExec> {
systemProperty(
"java.library.path",
"$projectDir/src/desktopMain/build/" + File.pathSeparator + System.getProperty("java.library.path"),
"$projectDir/src/desktopMain/resources/macos" +
File.pathSeparator +
"$projectDir/src/desktopMain/resources/windows" +
File.pathSeparator +
"$projectDir/src/desktopMain/resources/linux" +
File.pathSeparator +
System.getProperty("java.library.path"),
)
systemProperty(
"desktopUpdatesPublicKey",
gradleLocalProperties(rootDir, providers).getProperty("desktopUpdatesPublicKey"),
)
}

Expand Down
93 changes: 61 additions & 32 deletions composeApp/src/desktopMain/Makefile
Original file line number Diff line number Diff line change
@@ -1,81 +1,110 @@
# Makefile for NetworkTypeFinder JNI Bridge
# Makefile for NetworkTypeFinder and UpdateBridge JNI Bridges

# Variables
COMPILER = clang
FILES = c/NetworkTypeFinder.m
LIBRARY_NAME = networktypefinder
LIBRARY_FILE_MAC = lib$(LIBRARY_NAME).dylib
LIBRARY_FILE_LINUX = lib$(LIBRARY_NAME).so
NETWORK_FILES = c/NetworkTypeFinder.m
UPDATE_FILES_MAC = c/UpdateBridge.c
UPDATE_FILES_WIN = c/UpdateBridge.c c/WinSparkleBridge.c
NETWORK_LIBRARY_NAME = networktypefinder
UPDATE_LIBRARY_NAME = updatebridge
NETWORK_LIBRARY_FILE_MAC = lib$(NETWORK_LIBRARY_NAME).dylib
NETWORK_LIBRARY_FILE_LINUX = lib$(NETWORK_LIBRARY_NAME).so
UPDATE_LIBRARY_FILE_MAC = lib$(UPDATE_LIBRARY_NAME).dylib
UPDATE_LIBRARY_FILE_WIN = $(UPDATE_LIBRARY_NAME).dll
JAVA_HOME ?= $(shell java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home' | awk '{print $$3}')
RESOURCES_BASE_DIR = resources

# Detect platform
UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S),Darwin)
PLATFORM_TARGET := macos
LIBRARY_FILE := $(LIBRARY_FILE_MAC)
NETWORK_LIBRARY_FILE := $(NETWORK_LIBRARY_FILE_MAC)
UPDATE_LIBRARY_FILE := $(UPDATE_LIBRARY_FILE_MAC)
else ifeq ($(UNAME_S),Linux)
PLATFORM_TARGET := linux
LIBRARY_FILE := $(LIBRARY_FILE_LINUX)
NETWORK_LIBRARY_FILE := $(NETWORK_LIBRARY_FILE_LINUX)
UPDATE_LIBRARY_FILE :=
else ifeq ($(OS),Windows_NT)
PLATFORM_TARGET := windows
LIBRARY_FILE := $(LIBRARY_NAME).dll
NETWORK_LIBRARY_FILE := $(NETWORK_LIBRARY_NAME).dll
UPDATE_LIBRARY_FILE := $(UPDATE_LIBRARY_FILE_WIN)
else
PLATFORM_TARGET := unknown
LIBRARY_FILE :=
NETWORK_LIBRARY_FILE :=
UPDATE_LIBRARY_FILE :=
endif

# Default target: build only for detected platform
all: $(PLATFORM_TARGET)

macos:
@echo "Compiling Objective-C code to a dynamic library for macOS..."
@mkdir -p build
$(COMPILER) -dynamiclib -o build/$(LIBRARY_FILE_MAC) $(FILES) -framework Foundation -framework SystemConfiguration -framework CoreFoundation -framework Network -framework CFNetwork -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
@echo "Library created at build/$(LIBRARY_FILE_MAC)"
@echo "Compiling NetworkTypeFinder for macOS..."
@mkdir -p $(RESOURCES_BASE_DIR)/macos
$(COMPILER) -dynamiclib -o $(RESOURCES_BASE_DIR)/macos/$(NETWORK_LIBRARY_FILE_MAC) $(NETWORK_FILES) -framework Foundation -framework SystemConfiguration -framework CoreFoundation -framework Network -framework CFNetwork -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
@echo "NetworkTypeFinder library created at $(RESOURCES_BASE_DIR)/macos/$(NETWORK_LIBRARY_FILE_MAC)"
@echo "Compiling UpdateBridge for macOS..."
@mkdir -p $(RESOURCES_BASE_DIR)/macos
$(COMPILER) -dynamiclib -o $(RESOURCES_BASE_DIR)/macos/$(UPDATE_LIBRARY_FILE_MAC) $(UPDATE_FILES_MAC) \
-framework Foundation \
-I$(JAVA_HOME)/include \
-I$(JAVA_HOME)/include/darwin \
-install_name @loader_path/lib$(UPDATE_LIBRARY_NAME).dylib \
-Wl,-rpath,@loader_path
@echo "UpdateBridge library created at $(RESOURCES_BASE_DIR)/macos/$(UPDATE_LIBRARY_FILE_MAC)"

linux:
@echo "Compiling Objective-C code to a dynamic library for Linux..."
@mkdir -p build
$(COMPILER) -shared -fPIC -o build/$(LIBRARY_FILE_LINUX) $(FILES) -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
@echo "Library created at build/$(LIBRARY_FILE_LINUX)"
@echo "Compiling NetworkTypeFinder for Linux..."
@mkdir -p $(RESOURCES_BASE_DIR)/linux
$(COMPILER) -shared -fPIC -o $(RESOURCES_BASE_DIR)/linux/$(NETWORK_LIBRARY_FILE_LINUX) $(NETWORK_FILES) -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
@echo "NetworkTypeFinder library created at $(RESOURCES_BASE_DIR)/linux/$(NETWORK_LIBRARY_FILE_LINUX)"
@echo "UpdateBridge not supported on Linux"

windows:
@echo "Compiling Objective-C code to a dynamic library for Windows..."
@mkdir -p build
$(COMPILER) -shared -m64 -o build\\$(LIBRARY_NAME).dll $(FILES) '-I$(JAVA_HOME)\\include' '-I$(JAVA_HOME)\\include\\win32' -lws2_32 -liphlpapi
@echo "Library created at build/$(LIBRARY_NAME).dll"
@echo "Compiling NetworkTypeFinder for Windows..."
@mkdir -p $(RESOURCES_BASE_DIR)/windows
$(COMPILER) -shared -m64 -o $(RESOURCES_BASE_DIR)/windows/$(NETWORK_LIBRARY_NAME).dll $(NETWORK_FILES) '-I$(JAVA_HOME)\\include' '-I$(JAVA_HOME)\\include\\win32' -lws2_32 -liphlpapi
@echo "NetworkTypeFinder library created at $(RESOURCES_BASE_DIR)/windows/$(NETWORK_LIBRARY_NAME).dll"
@echo "Compiling UpdateBridge for Windows..."
$(COMPILER) -shared -m64 -o $(RESOURCES_BASE_DIR)/windows/$(UPDATE_LIBRARY_FILE_WIN) $(UPDATE_FILES_WIN) '-I$(JAVA_HOME)\\include' '-I$(JAVA_HOME)\\include\\win32'
@echo "UpdateBridge library created at $(RESOURCES_BASE_DIR)/windows/$(UPDATE_LIBRARY_FILE_WIN)"

# Install the library to system path
install: all
@echo "Installing library to system path..."
@echo "Installing libraries to system path..."
ifeq ($(PLATFORM_TARGET),macos)
cp build/$(LIBRARY_FILE_MAC) $(HOME)/Library/Java/Extensions
cp $(RESOURCES_BASE_DIR)/macos/$(NETWORK_LIBRARY_FILE_MAC) $(HOME)/Library/Java/Extensions
cp $(RESOURCES_BASE_DIR)/macos/$(UPDATE_LIBRARY_FILE_MAC) $(HOME)/Library/Java/Extensions
else ifeq ($(PLATFORM_TARGET),linux)
sudo cp build/$(LIBRARY_FILE_LINUX) /usr/lib/
sudo cp $(RESOURCES_BASE_DIR)/linux/$(NETWORK_LIBRARY_FILE_LINUX) /usr/lib/
else ifeq ($(PLATFORM_TARGET),windows)
copy build\\$(LIBRARY_NAME).dll %JAVA_HOME%\\bin
copy $(RESOURCES_BASE_DIR)\\windows\\$(NETWORK_LIBRARY_NAME).dll %JAVA_HOME%\\bin
copy $(RESOURCES_BASE_DIR)\\windows\\$(UPDATE_LIBRARY_FILE_WIN) %JAVA_HOME%\\bin
else
@echo "Unknown platform, not installing."
endif
@echo "Library installed"
@echo "Libraries installed"

clean:
@echo "Cleaning build artifacts..."
rm -rf build
rm -rf $(RESOURCES_BASE_DIR)
@echo "Clean complete"

help:
@echo "NetworkTypeFinder JNI Bridge Makefile"
@echo "NetworkTypeFinder and UpdateBridge JNI Bridges Makefile"
@echo ""
@echo "Targets:"
@echo " all (default): Compile Objective-C code to a dynamic library for the current platform"
@echo " install: Install the library to system path for the current platform"
@echo " all (default): Compile both libraries for the current platform"
@echo " install: Install the libraries to system path for the current platform"
@echo " clean: Clean build artifacts"
@echo " help: Show this help message"
@echo ""
@echo "Libraries built:"
@echo " NetworkTypeFinder: Network type detection"
@echo " UpdateBridge: Sparkle (macOS) / WinSparkle (Windows) integration"
@echo ""
@echo "Example usage:"
@echo " make all # Compile the library for your platform"
@echo " make install # Install the library for your platform"
@echo " make all # Compile the libraries for your platform"
@echo " make install # Install the libraries for your platform"

.PHONY: all macos linux windows install clean help
Binary file not shown.
Binary file not shown.
Loading
Loading