Skip to content

Commit

Permalink
Merge pull request #7 from fizzed/feature/blaze-build-scripts
Browse files Browse the repository at this point in the history
Feature/blaze build scripts
  • Loading branch information
jjlauer authored Oct 30, 2023
2 parents 0f64ed1 + 31defc2 commit 4c560dc
Show file tree
Hide file tree
Showing 16 changed files with 307 additions and 101 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
75 changes: 65 additions & 10 deletions .blaze/blaze.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,82 @@
import com.fizzed.blaze.Contexts;
import com.fizzed.blaze.Task;
import com.fizzed.buildx.Buildx;
import com.fizzed.buildx.ContainerBuilder;
import com.fizzed.buildx.Target;
import com.fizzed.jne.NativeTarget;
import com.fizzed.jne.OperatingSystem;
import org.slf4j.Logger;

import java.util.List;
import static java.util.Arrays.asList;
import java.nio.file.Path;
import java.util.List;

import static com.fizzed.blaze.Contexts.withBaseDir;
import static com.fizzed.blaze.Systems.exec;
import com.fizzed.buildx.*;
import static com.fizzed.blaze.Systems.*;
import static com.fizzed.blaze.util.Globber.globber;
import static java.util.Arrays.asList;

public class blaze {

private final Logger log = Contexts.logger();
private final Path projectDir = withBaseDir("../").toAbsolutePath();
private final NativeTarget localNativeTarget = NativeTarget.detect();
private final Path nativeDir = projectDir.resolve("native");
private final Path targetDir = projectDir.resolve("target");

@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();

log.info("Building natives for target {}", nativeTarget.toJneTarget());
log.info("Copying native code to (cleaned) {} directory...", targetDir);
rm(targetDir).recursive().force().run();
mkdir(targetDir).parents().run();
cp(globber(nativeDir, "*")).target(targetDir).recursive().debug().run();

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 exename = nativeTarget.resolveExecutableFileName("jcat");
final String libname = nativeTarget.resolveLibraryFileName("helloj");

if (nativeTarget.getOperatingSystem() == OperatingSystem.WINDOWS) {
// unfortunately its easiest to delegate this to helper script
exec("setup/build-native-lib-windows-action.bat", nativeTarget.toJneOsAbi(), nativeTarget.toJneArch())
.workingDir(this.projectDir)
.verbose()
.run();
} else {
String cmd = "make";
// freebsd and openbsd, we need to use gmake
if (nativeTarget.getOperatingSystem() == OperatingSystem.FREEBSD || nativeTarget.getOperatingSystem() == OperatingSystem.OPENBSD) {
cmd = "gmake";
}

log.info("Building jcat executable...");
exec(cmd).workingDir(targetJcatDir).debug().run();

log.info("Building helloj library...");
exec(cmd).workingDir(targetLibHelloJDir).debug().run();
}

cp(targetJcatDir.resolve(exename)).target(javaOutputDir).force().verbose().run();
cp(targetLibHelloJDir.resolve(libname)).target(javaOutputDir).force().verbose().run();
}

@Task(order = 2)
public void test() throws Exception {
/*exec("env")
.workingDir(projectDir)
.run();*/
exec("mvn", "test")
.workingDir(projectDir)
.workingDir(this.projectDir)
.verbose()
.run();
}

@Task(order = 3)
public void clean() throws Exception {
rm(this.targetDir).recursive().force().verbose().run();
}

private final List<Target> crossTargets = asList(
//
// Linux
Expand Down Expand Up @@ -212,14 +265,16 @@ public void cross_build_natives() throws Exception {
new Buildx(crossTargets)
.tags("build")
.execute((target, project) -> {
String buildScript = "setup/build-native-lib-linux-action.sh";
/*String buildScript = "setup/build-native-lib-linux-action.sh";
if (target.getOs().equals("macos")) {
buildScript = "setup/build-native-lib-macos-action.sh";
} else if (target.getOs().equals("windows")) {
buildScript = "setup/build-native-lib-windows-action.bat";
}
project.action(buildScript, target.getOs(), target.getArch()).run();
project.action(buildScript, target.getOs(), target.getArch()).run();*/

project.action("java", "-jar", "blaze.jar", "build_natives", "--target", target.getOsArch()).run();

// we know that the only modified file will be in the artifact dir
final String artifactRelPath = "src/test/resources/jne/" + target.getOs() + "/" + target.getArch() + "/";
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-ivy</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</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>com.fizzed</groupId>
<artifactId>blaze-core</artifactId>
<version>1.5.0</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.5.0</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.
8 changes: 0 additions & 8 deletions native/jcat/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#
# To run this in your own shell
# CC=gcc make
#

#CC = gcc
#CPP = g++

all:
$(CC) -Wall -pedantic -O2 -o jcat jcat.c

Expand Down
35 changes: 29 additions & 6 deletions native/libhelloj/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,36 @@
# 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)
EXTRA_CXXFLAGS := -z noexecstack
CXXFLAGS :=
CFLAGS :=
JAVA_INCLUDE := -I${JAVA_HOME}/include
ifeq ($(UNAME_S),Darwin)
JAVA_INCLUDE := ${JAVA_INCLUDE} -I${JAVA_HOME}/include/darwin
SHAREDFILEEXT = dylib
EXTRA_CXXFLAGS =
endif
ifeq ($(UNAME_S),Linux)
JAVA_INCLUDE := ${JAVA_INCLUDE} -I${JAVA_HOME}/include/linux
endif
ifeq ($(UNAME_S),FreeBSD)
JAVA_INCLUDE := ${JAVA_INCLUDE} -I${JAVA_HOME}/include/freebsd
CXX = clang++
endif
ifeq ($(UNAME_S),OpenBSD)
JAVA_INCLUDE := ${JAVA_INCLUDE} -I${JAVA_HOME}/include/openbsd
EXTRA_CXXFLAGS =
CXX = clang++
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
$(CXX) -shared -fPIC -Wall -pedantic -O3 $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(JAVA_INCLUDE) -o libhelloj.$(SHAREDFILEEXT) -lc helloj_HelloLib.cpp

jniheaders:
$(JAVAC) -h . helloj/HelloLib.java
Expand All @@ -21,4 +43,5 @@ test:

clean:
rm -f libhelloj.so
rm -f helloj/*.class
rm -f libhelloj.dylib
rm -f helloj/*.class
25 changes: 0 additions & 25 deletions setup/build-native-lib-linux-action.sh

This file was deleted.

25 changes: 0 additions & 25 deletions setup/build-native-lib-macos-action.sh

This file was deleted.

7 changes: 1 addition & 6 deletions setup/build-native-lib-windows-action.bat
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,4 @@ cd .\target\jcat
nmake -f VCMakefile

cd ..\libhelloj
nmake -f VCMakefile

cd ..
set OUTPUT_DIR="..\src\test\resources\jne\%BUILDOS%\%BUILDARCH%"
copy jcat\jcat.exe "%OUTPUT_DIR%"
copy libhelloj\helloj.dll "%OUTPUT_DIR%"
nmake -f VCMakefile
Loading

0 comments on commit 4c560dc

Please sign in to comment.