Skip to content

Commit

Permalink
Initial work on cross platform build
Browse files Browse the repository at this point in the history
  • Loading branch information
jjlauer committed Oct 27, 2023
1 parent 0f64ed1 commit 5963560
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 25 deletions.
10 changes: 6 additions & 4 deletions .blaze/blaze.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
blaze.dependencies = [
"com.fizzed:blaze-ssh:1.1.0"
"com.fizzed:buildx:1.0.3"
"com.fizzed:jne:4.0.2"
]
"com.fizzed:blaze-ssh"
"com.fizzed:buildx:RELEASE"
"com.fizzed:jne:RELEASE"
]

java.source.version = 8
47 changes: 47 additions & 0 deletions .blaze/blaze.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import com.fizzed.blaze.Context;
import com.fizzed.blaze.Contexts;
import com.fizzed.blaze.Task;
import com.fizzed.blaze.system.Copy;
import com.fizzed.jne.NativeTarget;

import java.nio.file.Files;
import java.util.List;
import static java.util.Arrays.asList;
import java.nio.file.Path;
Expand All @@ -14,6 +18,49 @@ public class blaze {
private final Path projectDir = withBaseDir("../").toAbsolutePath();
private final NativeTarget localNativeTarget = NativeTarget.detect();

@Task(order = 1)
public void build_natives() throws Exception {
final String targetStr = Contexts.config().value("target").orNull();
final NativeTarget nativeTarget = targetStr != null ? NativeTarget.fromJneTarget(targetStr) : NativeTarget.detect();
final Path nativeDir = projectDir.resolve("native");
final Path targetDir = projectDir.resolve("target");
final Path targetJcatDir = targetDir.resolve("jcat");
final Path targetLibHelloJDir = targetDir.resolve("libhelloj");
final Path javaOutputDir = withBaseDir("../src/test/resources/jne/" + nativeTarget.toJneOsAbi() + "/" + nativeTarget.toJneArch());
final String libname = nativeTarget.resolveLibraryFileName("helloj");

Files.createDirectories(targetDir);

exec("rsync", "-avrt", "--delete", nativeDir+"/", targetDir+"/").run();

exec("make").workingDir(targetJcatDir).run();

exec("make").workingDir(targetLibHelloJDir)
.env("CXXFLAGS", "-z noexecstack")
.run();

new Copy(Contexts.currentContext())
.source(targetJcatDir.resolve("jcat"))
.destination(javaOutputDir)
.force()
.run();

new Copy(Contexts.currentContext())
.source(targetLibHelloJDir.resolve(libname))
.destination(javaOutputDir)
.force()
.run();

//Files.createDirectories(javaOutputDir);
//Files.copy(targetJcatDir.resolve("jcat"), javaOutputDir.resolve("jcat"));

/*cd ..
OUTPUT_DIR="../src/test/resources/jne/${BUILDOS}/${BUILDARCH}"
mkdir -p "$OUTPUT_DIR"
cp jcat/jcat "$OUTPUT_DIR"
cp libhelloj/libhelloj.so "$OUTPUT_DIR"*/
}

@Task(order = 2)
public void test() throws Exception {
/*exec("env")
Expand Down
69 changes: 52 additions & 17 deletions .blaze/pom.xml
Original file line number Diff line number Diff line change
@@ -1,44 +1,79 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>blaze</groupId>
<artifactId>jne-blaze</artifactId>
<name>jne-blaze</name>
<version>0.0.1</version>

<!--
THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT BY HAND!
Edit or create a <blaze-script>.conf file, and re-run the generate-maven-project command.
-->

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.install.skip>true</maven.install.skip>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<build>
<sourceDirectory>${project.basedir}</sourceDirectory>
<sourceDirectory>${project.basedir}</sourceDirectory>
</build>

<dependencies>
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>blaze-lite</artifactId>
<version>1.1.0</version>
<artifactId>blaze-core</artifactId>
<version>1.4.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>blaze-ivy</artifactId>
<version>1.4.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.ivy</groupId>
<artifactId>ivy</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-exec</artifactId>
<version>1.12</version>
</dependency>
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>blaze-ssh</artifactId>
<version>1.1.0</version>
<version>1.4.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>buildx</artifactId>
<version>1.0.3</version>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>jne</artifactId>
<version>4.0.2</version>
<version>RELEASE</version>
</dependency>
</dependencies>

</project>
Binary file modified blaze.jar
Binary file not shown.
12 changes: 8 additions & 4 deletions native/libhelloj/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
# CC=gcc CXX=g++ make
#

#CC = gcc
#CPP = g++
JAVAC = javac
JAVA = java
CC ?= gcc
CPP ?= g++
JAVAC ?= javac
JAVA ?= java
SHAREDFILEEXT ?= so
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SHAREDFILEEXT = dylib
endif

all:
$(CXX) -shared -fPIC -Wall -pedantic -O3 $(CXXFLAGS) -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux -I${JAVA_HOME}/include/darwin -I${JAVA_HOME}/include/freebsd -I${JAVA_HOME}/include/openbsd -o libhelloj.$(SHAREDFILEEXT) -lc helloj_HelloLib.cpp
Expand Down
Binary file modified src/test/resources/jne/linux/x64/jcat
Binary file not shown.
Binary file modified src/test/resources/jne/linux/x64/libhelloj.so
Binary file not shown.
Binary file modified src/test/resources/jne/windows/arm64/helloj.dll
Binary file not shown.
Binary file modified src/test/resources/jne/windows/arm64/jcat.exe
Binary file not shown.
Binary file modified src/test/resources/jne/windows/x64/helloj.dll
Binary file not shown.
Binary file modified src/test/resources/jne/windows/x64/jcat.exe
Binary file not shown.

0 comments on commit 5963560

Please sign in to comment.