Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build native lib for arm64 #8

Merged
merged 3 commits into from
May 3, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}

- name: Build without tests
run: ./gradlew build -PreleaseVersion=${{ steps.get_version.outputs.VERSION }} -x test -x spotlessCheck
run: ./gradlew build -PreleaseNativeLibs -PreleaseVersion=${{ steps.get_version.outputs.VERSION }} -x test -x spotlessCheck
fab-10 marked this conversation as resolved.
Show resolved Hide resolved
env:
JAVA_OPTS: -Xmx2g -Dorg.gradle.daemon=false

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Linux/MacOs
Windows
* Requirement [Docker Desktop WSL 2 backend on Windows](https://docs.docker.com/desktop/wsl/)

On release native libs are build for all the supported platforms,
if you want to test this process locally run `./gradlew -PreleaseNativeLibs jar`,
jar is generated in `arithmetization/build/libs`.

### Install Rust

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void transactionOverModuleLineCountNotAccepted() throws Exception {

assertThat(signedTxContractInteractionResp.hasError()).isTrue();
assertThat(signedTxContractInteractionResp.getError().getMessage())
.isEqualTo("Transaction line count for module ADD=2018 is above the limit 70");
.isEqualTo("Transaction line count for module ADD=402 is above the limit 70");

assertThat(getTxPoolContent()).isEmpty();

Expand Down
File renamed without changes.
10 changes: 8 additions & 2 deletions native/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@ OSTYPE=$(uname -o)

# delete old build dir, if exists
rm -rf "$SCRIPTDIR/compress/build/native" || true
mkdir -p "$SCRIPTDIR/compress/build/native"

ARCH_DIR=""

if [ x"$OSTYPE" = x"msys" ]; then
LIBRARY_EXTENSION=dll
elif [ x"$OSTYPE" = x"GNU/Linux" ]; then
LIBRARY_EXTENSION=so
ARCHITECTURE="$(uname --machine)"
ARCH_DIR="linux-$ARCHITECTURE"
elif [ x"$OSTYPE" = x"Darwin" ]; then
LIBRARY_EXTENSION=dylib
else
echo "*** Unknown OS: $OSTYPE"
exit 1
fi

DEST_DIR="$SCRIPTDIR/compress/build/native/$ARCH_DIR"
mkdir -p "$DEST_DIR"

cd "$SCRIPTDIR/compress/compress-jni"
echo "Building Go module libcompress_jni.$LIBRARY_EXTENSION for $OSTYPE"
CGO_ENABLED=1 go build -buildmode=c-shared -o libcompress_jni.$LIBRARY_EXTENSION compress-jni.go
mv libcompress_jni.* "$SCRIPTDIR/compress/build/native"
mv libcompress_jni.* "$DEST_DIR"
26 changes: 9 additions & 17 deletions native/compress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ test {
}

tasks.register('buildJNI', Exec) {
if(org.gradle.internal.os.OperatingSystem.current().isWindows()) {
if(project.hasProperty("releaseNativeLibs")) {
workingDir buildscript.sourceFile.parentFile.parentFile
commandLine 'wsl', './wsl.sh'
commandLine 'sh', '-c', './release.sh'
} else if(org.gradle.internal.os.OperatingSystem.current().isWindows()) {
workingDir buildscript.sourceFile.parentFile.parentFile
commandLine 'wsl', './release.sh'
} else {
workingDir buildscript.sourceFile.parentFile
commandLine 'sh', '-c', '../build.sh'
workingDir buildscript.sourceFile.parentFile.parentFile
commandLine 'sh', '-c', './build.sh'
}
}

Expand Down Expand Up @@ -70,13 +73,13 @@ tasks.register('macLibCopy', Copy) {
processResources.dependsOn macLibCopy

tasks.register('linuxLibCopy', Copy) {
from 'build/native/libcompress_jni.so'
from 'build/native/linux-x86_64/libcompress_jni.so'
into 'build/resources/main/linux-x86-64'
}
processResources.dependsOn linuxLibCopy

tasks.register('linuxArm64LibCopy', Copy) {
from 'build/native/libcompress_jni.so'
from 'build/native/linux-aarch64/libcompress_jni.so'
into 'build/resources/main/linux-aarch64'
}
processResources.dependsOn linuxArm64LibCopy
Expand All @@ -102,14 +105,3 @@ jar {
}

jar.dependsOn(buildJNI)

sourceSets {
main {
resources {
srcDirs '${buildDir}/darwin-aaarch64'
srcDirs '${buildDir}/darwin-x86-64'
srcDirs '${buildDir}/linux-gnu-x86_64'
srcDirs '${buildDir}/linux-gnu-aarch64'
}
}
}
32 changes: 32 additions & 0 deletions native/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash -x

docker build -f Dockerfile-dockcross --build-arg IMAGE=windows-shared-x64 -t native-windows-shared-x64-cross-compile .
docker build -f Dockerfile-dockcross --build-arg IMAGE=linux-x64 -t native-linux-x64-cross-compile .
docker build -f Dockerfile-dockcross --build-arg IMAGE=linux-arm64 -t native-linux-arm64-cross-compile .

mkdir -p compress/build/native/linux-x86_64
mkdir -p compress/build/native/linux-aarch64

docker run --rm native-windows-shared-x64-cross-compile > compress/build/native/native-windows-shared-x64-cross-compile
docker run --rm native-linux-x64-cross-compile > compress/build/native/native-linux-x64-cross-compile
docker run --rm native-linux-arm64-cross-compile > compress/build/native/native-linux-arm64-cross-compile

chmod +x \
compress/build/native/native-windows-shared-x64-cross-compile \
compress/build/native/native-linux-x64-cross-compile \
compress/build/native/native-linux-arm64-cross-compile

OCI_EXE=docker \
compress/build/native/native-windows-shared-x64-cross-compile --image native-windows-shared-x64-cross-compile \
bash -c "cd compress/compress-jni &&
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -buildmode=c-shared -o ../build/native/compress_jni.dll compress-jni.go"

OCI_EXE=docker \
compress/build/native/native-linux-x64-cross-compile --image native-linux-x64-cross-compile \
bash -c "cd compress/compress-jni &&
CGO_ENABLED=1 go build -buildmode=c-shared -o ../build/native/linux-x86_64/libcompress_jni.so compress-jni.go"

OCI_EXE=docker \
compress/build/native/native-linux-arm64-cross-compile --image native-linux-arm64-cross-compile \
bash -c "cd compress/compress-jni &&
CGO_ENABLED=1 GOARCH=arm64 go build -buildmode=c-shared -o ../build/native/linux-aarch64/libcompress_jni.so compress-jni.go"
17 changes: 0 additions & 17 deletions native/wsl.sh

This file was deleted.

Loading