Skip to content

Commit

Permalink
Merge pull request #44 from Qualytics/master
Browse files Browse the repository at this point in the history
Refactor this repo for modernity
  • Loading branch information
albarrentine authored Mar 27, 2024
2 parents 60a8b6f + 8f4ea71 commit 3673d0e
Show file tree
Hide file tree
Showing 22 changed files with 142 additions and 423 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/build-gradle-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build this project with gradle

on:
push:

jobs:
build-gradle-project:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: openvenues/libpostal
path: libpostal
- name: Install libtool
run: |
cd libpostal
./bootstrap.sh
mkdir data_dir
./configure --datadir=`pwd`/data_dir MODEL=senzing
sudo make -j4
sudo make install
sudo ldconfig
- uses: actions/checkout@v4
with:
repository: Qualytics/jpostal
path: jpostal
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Run build with Gradle Wrapper
run: |
cd jpostal
./gradlew check
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/.idea/
/build/
/.gradle/
32 changes: 0 additions & 32 deletions .travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions Makefile.am

This file was deleted.

30 changes: 4 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,6 @@ sudo ldconfig

Note: libpostal >= v0.3.3 is required to use this binding.

Make sure pkg-config can find libpostal
---------------------------------------

Some users have reported issues with the jpostal build related to pkg-config.

For jpostal to build, make sure this command runs without any errors:

```shell
pkg-config --cflags --libs libpostal
```

If you get a message like `No package 'libpostal' found`, try the following:

```shell
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
```

Try the `pkg-config --cflags --libs libpostal` command again. If it still can't find libpostal, return to the libpostal checkout directory and try:

```shell
export PKG_CONFIG_PATH=$(pwd)
```

Building jpostal
----------------
Expand All @@ -112,19 +90,19 @@ Only one command is needed:
./gradlew assemble
```

This will implicitly run [build.sh](./build.sh) which automatically runs the Autotools build for the JNI/C portion of the library and installs the resulting shared libraries in the expected location for java.library.path
This will leverage gradle's NativeLibrarySpec support to build for the JNI/C portion of the library and installs the resulting shared libraries in the expected location for java.library.path

Usage in a Java project
-----------------------

The JNI portion of jpostal builds shared object files (.so on Linux, .jniLib on Mac) that need to be on java.library.path. After running ```gradle assemble``` the .so/.jniLib files can be found under ```src/main/jniLibs``` in the checkout dir. For running the tests, we set java.library.path explicitly [here](https://github.com/openvenues/jpostal/blob/master/build.gradle#L18).
The JNI portion of jpostal builds shared object files (.so on Linux, .jniLib on Mac) that need to be on java.library.path.
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).

For gradle users, there's a plugin called gradle-natives that may be helpful: https://github.com/cjstehno/coffeaelectronica/wiki/Going-Native-with-Gradle

Compatibility
-------------

Building jpostal is known to work on Linux and Mac OSX. The Travis CI build tests Oracle JDK 7/8 and OpenJDK 7.
Building jpostal is known to work on Linux and Mac OSX (including Mac silicon).

Tests
-----
Expand Down
2 changes: 0 additions & 2 deletions bootstrap.sh

This file was deleted.

57 changes: 51 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,64 @@
apply plugin: 'java'
import org.gradle.internal.jvm.Jvm

plugins {
id 'c'
id 'java'
id 'application'
}

repositories {
mavenCentral()
}

task buildJniLib(type:Exec) {
commandLine './build.sh'
sourceSets.main.java.srcDirs = ["src/main/java"]
sourceSets.test.java.srcDirs = ["src/test/java"]

model {
platforms {
x64 {
architecture "x86_64"
}
}

components {
jpostal(NativeLibrarySpec) {
binaries.all {
def jvmHome = org.gradle.internal.jvm.Jvm.current().javaHome
if (targetPlatform.operatingSystem.macOsX) {
cCompiler.args '-I', "${jvmHome}/include"
cCompiler.args '-I', "${jvmHome}/include/darwin"
cCompiler.args '-mmacosx-version-min=10.9'
linker.args '-mmacosx-version-min=10.9'
linker.args '-stdlib=libc++'
} else if (targetPlatform.operatingSystem.linux) {
cCompiler.args '-I', "${jvmHome}/include"
cCompiler.args '-I', "${jvmHome}/include/linux"
cCompiler.args '-D_FILE_OFFSET_BITS=64'
} else if (targetPlatform.operatingSystem.windows) {
cCompiler.args "-I${jvmHome}/include"
cCompiler.args "-I${jvmHome}/include/win32"
} else if (targetPlatform.operatingSystem.freeBSD) {
cCompiler.args '-I', "${jvmHome}/include"
cCompiler.args '-I', "${jvmHome}/include/freebsd"
}
linker.args '-lpostal' // Link with libpostal
}
}
}
}

classes.dependsOn 'jpostalSharedLibrary'


application {
applicationDefaultJvmArgs = ["-Djava.library.path=" + file("${buildDir}/libs/jpostal/shared").absolutePath]
}

compileJava.dependsOn(buildJniLib)

dependencies {
testCompile 'junit:junit:4.+'
testImplementation 'junit:junit:4.+'
}

tasks.withType(Test) {
systemProperty "java.library.path", "src/main/jniLibs"
systemProperty "java.library.path", file("${buildDir}/libs/jpostal/shared").absolutePath
}
4 changes: 0 additions & 4 deletions build.sh

This file was deleted.

50 changes: 0 additions & 50 deletions configure.ac

This file was deleted.

45 changes: 45 additions & 0 deletions dependencies/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# Install [libpostal](https://github.com/openvenues/libpostal) on a base image with a JDK
# to support automated builds of the jpostal project
#
# Note: An image built with this dockerfile is available publicly on Dockerhub as qualytics42/qualytics-jpostal-base:0.1.0
# built with `docker buildx build --platform linux/arm64,linux/amd64 .` on a M1 Mac
#
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
FROM cimg/openjdk:17.0

USER 0

RUN set -ex; \
mkdir -p /home; \
cd /home; \
apt-get update; \
apt-get install -y build-essential curl autoconf automake libtool pkg-config git zip; \
git clone https://github.com/openvenues/libpostal; \
cd libpostal; \
./bootstrap.sh; \
mkdir data_dir; \
# ./configure --datadir=`pwd`/data_dir MODEL=senzing; \
# sse2 is not available when building on M1 Mac
./configure --datadir=`pwd`/data_dir MODEL=senzing --disable-sse2; \
make -j4; \
make install; \
chown -R circleci ../libpostal \
ldconfig;

USER circleci
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Fri Feb 19 02:42:10 EST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip
Loading

0 comments on commit 3673d0e

Please sign in to comment.