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
54 changes: 54 additions & 0 deletions .github/workflows/build_networktypefinder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build NetworkTypeFinder JNI Bridge

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

jobs:
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
defaults:
run:
working-directory: composeApp/src/desktopMain
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'

- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y clang make

- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: brew install llvm make

- name: Install dependencies (Windows)
if: runner.os == 'Windows'
run: choco install llvm make

- name: Build NetworkTypeFinder
run: make all

- name: Upload built library
uses: actions/upload-artifact@v4
with:
name: networktypefinder-${{ matrix.os }}
path: composeApp/src/desktopMain/build/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ captures
.kotlin
Gemfile.lock
output
!composeApp/src/desktopMain/build/libnetworktypefinder.dylib
!composeApp/src/desktopMain/build/libnetworktypefinder.so
!composeApp/src/desktopMain/build/networktypefinder.dll
17 changes: 17 additions & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,23 @@ tasks {
}
}

val makeLibrary by tasks.registering(Exec::class) {
workingDir = file("src/desktopMain")
commandLine = listOf("make", "all")
}

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

tasks.withType<JavaExec> {
systemProperty(
"java.library.path",
"$projectDir/src/desktopMain/build/" + File.pathSeparator + System.getProperty("java.library.path"),
)
}

tasks.register("copyBrandingToCommonResources") {
doLast {
val projectDir = project.projectDir.absolutePath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

logo_probe.xml
ooni_logo.xml
ooni_logo.xml
logo_probe.xml
4 changes: 2 additions & 2 deletions composeApp/src/commonMain/res/drawable/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

ic_launcher_monochrome.xml
ic_launcher_foreground.xml
notification_icon.xml
ic_launcher_monochrome.xml
notification_icon.xml
81 changes: 81 additions & 0 deletions composeApp/src/desktopMain/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Makefile for NetworkTypeFinder JNI Bridge

# Variables
COMPILER = clang
FILES = c/NetworkTypeFinder.m
LIBRARY_NAME = networktypefinder
LIBRARY_FILE_MAC = lib$(LIBRARY_NAME).dylib
LIBRARY_FILE_LINUX = lib$(LIBRARY_NAME).so
JAVA_HOME ?= $(shell java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home' | awk '{print $$3}')

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

ifeq ($(UNAME_S),Darwin)
PLATFORM_TARGET := macos
LIBRARY_FILE := $(LIBRARY_FILE_MAC)
else ifeq ($(UNAME_S),Linux)
PLATFORM_TARGET := linux
LIBRARY_FILE := $(LIBRARY_FILE_LINUX)
else ifeq ($(OS),Windows_NT)
PLATFORM_TARGET := windows
LIBRARY_FILE := $(LIBRARY_NAME).dll
else
PLATFORM_TARGET := unknown
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)"

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)"

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"

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

clean:
@echo "Cleaning build artifacts..."
rm -rf build
@echo "Clean complete"

help:
@echo "NetworkTypeFinder JNI Bridge 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 " clean: Clean build artifacts"
@echo " help: Show this help message"
@echo ""
@echo "Example usage:"
@echo " make all # Compile the library for your platform"
@echo " make install # Install the library for your platform"

.PHONY: all macos linux windows install clean help
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions composeApp/src/desktopMain/c/NetworkTypeFinder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef NetworkTypeFinder_h
#define NetworkTypeFinder_h

#include <jni.h>

#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT jstring JNICALL Java_org_ooni_engine_MacOsNetworkTypeFinder_getNetworkType(JNIEnv *env, jobject obj);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not just MacOs right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes


#ifdef __cplusplus
}
#endif
#endif
Loading
Loading