Skip to content

Commit 06a4ff7

Browse files
committed
Added multi-platform package, publishing
1 parent 0457c9d commit 06a4ff7

File tree

29 files changed

+1292
-456
lines changed

29 files changed

+1292
-456
lines changed

.github/workflows/build-gradle-project.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: Build & Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
build:
10+
name: Build Platform-Specific JARs
11+
strategy:
12+
matrix:
13+
include:
14+
- os: ubuntu-latest
15+
platform: linux-x86_64
16+
build-tools: build-essential clang pkg-config
17+
- os: ubuntu-latest
18+
platform: linux-aarch64
19+
build-tools: build-essential clang pkg-config gcc-aarch64-linux-gnu
20+
cross-compile: true
21+
- os: macos-latest
22+
platform: macos-aarch64
23+
build-tools: ""
24+
runs-on: ${{ matrix.os }}
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v5
29+
30+
- name: Install build tools (Linux)
31+
if: startsWith(matrix.os, 'ubuntu')
32+
run: |
33+
sudo apt-get update
34+
sudo apt-get install -y ${{ matrix.build-tools }}
35+
36+
- name: Setup Java
37+
uses: actions/setup-java@v5
38+
with:
39+
distribution: temurin
40+
java-version: 21
41+
cache: gradle
42+
43+
- name: Setup Gradle
44+
uses: gradle/actions/setup-gradle@v4
45+
46+
- name: Set up cross-compilation (Linux ARM64)
47+
if: matrix.platform == 'linux-aarch64'
48+
run: |
49+
echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
50+
echo "CXX=aarch64-linux-gnu-g++" >> $GITHUB_ENV
51+
echo "TARGET_OS=linux" >> $GITHUB_ENV
52+
echo "TARGET_ARCH=aarch64" >> $GITHUB_ENV
53+
54+
- name: Set platform environment variables
55+
run: |
56+
case "${{ matrix.platform }}" in
57+
linux-x86_64)
58+
echo "TARGET_OS=linux" >> $GITHUB_ENV
59+
echo "TARGET_ARCH=x86_64" >> $GITHUB_ENV
60+
;;
61+
macos-aarch64)
62+
echo "TARGET_OS=macos" >> $GITHUB_ENV
63+
echo "TARGET_ARCH=aarch64" >> $GITHUB_ENV
64+
;;
65+
esac
66+
67+
- name: Build jpostal
68+
run: ./gradlew -Pversion=${{ github.event.release.tag_name }} clean build platformJar -x test
69+
70+
- name: Upload platform artifacts
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: jpostal-${{ matrix.platform }}
74+
path: build/libs/*.jar
75+
76+
publish:
77+
name: Publish to Maven
78+
needs: build
79+
runs-on: ubuntu-latest
80+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
81+
82+
steps:
83+
- name: Checkout
84+
uses: actions/checkout@v5
85+
86+
- name: Download all artifacts
87+
uses: actions/download-artifact@v5
88+
with:
89+
path: artifacts
90+
91+
- name: Setup Java
92+
uses: actions/setup-java@v5
93+
env:
94+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
95+
with:
96+
distribution: temurin
97+
java-version: 21
98+
cache: gradle
99+
gpg-passphrase: GPG_PASSPHRASE
100+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
101+
102+
- name: Setup Gradle
103+
uses: gradle/actions/setup-gradle@v4
104+
105+
- name: Prepare artifacts for publishing
106+
run: |
107+
mkdir -p build/libs
108+
find artifacts -name "*.jar" -exec cp {} build/libs/ \;
109+
ls -la build/libs/
110+
111+
- name: Publish
112+
env:
113+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
114+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116+
run: ./gradlew publish
117+
118+
- name: Create GitHub Release
119+
uses: softprops/action-gh-release@v2
120+
with:
121+
files: build/libs/*.jar
122+
generate_release_notes: true
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Dependency Submission
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
dependency-submission:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v5
17+
18+
- name: Setup Java
19+
uses: actions/setup-java@v5
20+
with:
21+
distribution: 'temurin'
22+
java-version: 17
23+
cache: gradle
24+
25+
- name: Generate and submit dependency graph
26+
uses: gradle/actions/dependency-submission@v4

README.md

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,56 @@ jpostal
55

66
These are the Java/JNI bindings to [libpostal](https://github.com/openvenues/libpostal), a fast, multilingual NLP library (written in C) for parsing/normalizing physical addresses around the world.
77

8+
## Automatic Platform Detection
9+
10+
This library automatically detects your platform and loads the correct native libraries at runtime. Simply add the dependency - no platform specification required!
11+
12+
### Maven/Gradle Usage (Recommended)
13+
14+
**Maven:**
15+
```xml
16+
<dependency>
17+
<groupId>com.matchory.packages</groupId>
18+
<artifactId>jpostal</artifactId>
19+
<version>1.0.0</version>
20+
</dependency>
21+
```
22+
23+
**Gradle:**
24+
```gradle
25+
implementation 'com.matchory.packages:jpostal:1.0.0'
26+
```
27+
28+
The universal JAR includes native libraries for all supported platforms:
29+
- Linux x86_64 and ARM64 (aarch64)
30+
- macOS Apple Silicon (aarch64)
31+
32+
### Platform-Specific JARs (Optional)
33+
34+
For smaller deployments, platform-specific JARs are also available:
35+
36+
**Maven:**
37+
```xml
38+
<dependency>
39+
<groupId>com.matchory.packages</groupId>
40+
<artifactId>jpostal</artifactId>
41+
<version>1.0.0</version>
42+
<classifier>linux-x86_64</classifier> <!-- or linux-aarch64, macos-aarch64 -->
43+
</dependency>
44+
```
45+
46+
**Gradle:**
47+
```gradle
48+
implementation 'com.matchory.packages:jpostal:1.0.0:linux-x86_64' // or your target platform
49+
```
50+
851
Usage
952
-----
1053

1154
To expand address strings into normalized forms suitable for geocoder queries:
1255

1356
```java
14-
import com.mapzen.jpostal.AddressExpander;
57+
import com.matchory.packages.jpostal.AddressExpander;
1558

1659
// Singleton, libpostal setup is done in the constructor
1760
AddressExpander e = AddressExpander.getInstance();
@@ -21,7 +64,7 @@ String[] expansions = e.expandAddress("Quatre vingt douze Ave des Champs-Élysé
2164
To parse addresses into components:
2265

2366
```java
24-
import com.mapzen.jpostal.AddressParser;
67+
import com.matchory.packages.jpostal.AddressParser;
2568

2669
// Singleton, parser setup is done in the constructor
2770
AddressParser p = AddressParser.getInstance();
@@ -36,17 +79,45 @@ To use a libpostal installation with a datadir known at setup-time:
3679

3780
```java
3881

39-
import com.mapzen.jpostal.AddressParser;
40-
import com.mapzen.jpostal.AddressExpander;
82+
import com.matchory.packages.jpostal.AddressParser;
83+
import com.matchory.packages.jpostal.AddressExpander;
4184

4285
AddressExpander e = AddressExpander.getInstanceDataDir("/some/path");
4386
AddressParser p = AddressParser.getInstanceDataDir("/some/path");
4487
```
4588

46-
Building libpostal
47-
------------------
89+
Building Platform-Specific JARs
90+
--------------------------------
91+
92+
This project uses a matrix build system to create platform-specific JARs. Each JAR contains:
93+
94+
1. **Pre-built libpostal native libraries** for the target platform (from `libs/libpostal/`)
95+
2. **JNI bindings** built by Gradle for the target platform
96+
97+
### Local Development
98+
99+
For local development on your current platform:
100+
```bash
101+
./gradlew clean build
102+
```
103+
104+
### Cross-Platform Building
105+
106+
To build for a specific platform (useful in CI):
107+
```bash
108+
TARGET_OS=linux TARGET_ARCH=x86_64 ./gradlew clean jar -x test
109+
TARGET_OS=linux TARGET_ARCH=aarch64 ./gradlew clean jar -x test
110+
TARGET_OS=macos TARGET_ARCH=aarch64 ./gradlew clean jar -x test
111+
```
112+
113+
### GitHub Actions Matrix Build
114+
115+
The project includes a GitHub Actions workflow that automatically builds JARs for all supported platforms when you create a release tag.
116+
117+
Building libpostal (Development)
118+
-------------------------------
48119

49-
Before building the Java bindings, you must install the libpostal C library. Make sure you have the following prerequisites:
120+
For development purposes, you may want to build libpostal from source. Make sure you have the following prerequisites:
50121

51122
**On Ubuntu/Debian**
52123
```
@@ -95,15 +166,15 @@ This will leverage gradle's NativeLibrarySpec support to build for the JNI/C por
95166
Usage in a Java project
96167
-----------------------
97168

98-
The JNI portion of jpostal builds shared object files (.so on Linux, .jniLib on Mac) that need to be on java.library.path.
169+
The JNI portion of jpostal builds shared object files (.so on Linux, .jniLib on Mac) that need to be on java.library.path.
99170
After running ```gradle assemble``` the .so/.jniLib files can be found under ```./libs/jpostal/shared``` in the build dir. For running the tests, we set java.library.path explicitly [here](https://github.com/Qualytics/jpostal/blob/master/build.gradle#L63).
100171

101172

102173
Compatibility
103174
-------------
104175

105176
- Building jpostal is known to work on Linux and Mac OSX (including Mac silicon).
106-
- Requires JDK 16 or later. Make sure JAVA_HOME points to JDK 16+.
177+
- Requires JDK 16 or later. Make sure JAVA_HOME points to JDK 16+.
107178

108179

109180
Tests

0 commit comments

Comments
 (0)