Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #50 from sgrouples/unfinished_develop
Browse files Browse the repository at this point in the history
Add aarch64 support
  • Loading branch information
pfrank13 authored Mar 18, 2024
2 parents 2460c76 + 648e60e commit a697b0f
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 42 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/deploy-javadoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
- uses: actions/cache@v4
with:
java-version: '8'
distribution: 'temurin'

path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.rustup
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Generate Javadoc
run: gradle aggregateJavadoc
run: nix develop --command bash -c "./gradlew aggregateJavadoc"

- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
26 changes: 17 additions & 9 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ jobs:
packages: write

steps:
- name: Output GLIBC Version
run: ldd --version
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
java-version: '8'
distribution: 'temurin'

path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.rustup
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build with Gradle
run: gradle -i build
run: nix develop --ignore-environment --command bash -c "./gradlew build"
env:
USERNAME: ${{ github.actor }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}

25 changes: 13 additions & 12 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ jobs:
packages: write

steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
java-version: '8'
distribution: 'temurin'

path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.rustup
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build with Gradle
run: gradle -i build

# The USERNAME and TOKEN need to correspond to the credentials environment variables used in
# the publishing section of your build.gradle
- name: Publish to GitHub Packages
run: gradle publish
run: nix develop --ignore-environment --keep USERNAME --keep TOKEN --command bash -c "./gradlew build && ./gradlew publish"
env:
USERNAME: ${{ github.actor }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
43 changes: 32 additions & 11 deletions crypto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,41 @@ test {
task compileRust {
project.logger.info("#####################" + System.getProperty("os.name").toLowerCase())
doLast {
if(System.getProperty("os.name").toLowerCase().contains("linux")) {
// nix build detection
if (System.getenv('NIX_CC') != null) {
exec {
workingDir 'src/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target=x86_64-unknown-linux-gnu', '--target-dir=../../build/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target=aarch64-unknown-linux-gnu', '--target-dir=../../build/jni-crypto'
}
}
else if (System.getProperty("os.name").toLowerCase().contains("windows")) {
exec {
workingDir 'src/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target=x86_64-pc-windows-gnu', '--target-dir=../../build/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target=x86_64-unknown-linux-gnu', '--target-dir=../../build/jni-crypto'
}
}
// Does not cover solaris, just MacOS. See potential return types here:
// https://docs.gradle.org/current/javadoc/org/gradle/nativeplatform/platform/OperatingSystem.html
else {
exec {
workingDir 'src/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target-dir=../../build/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target=x86_64-pc-windows-gnu', '--target-dir=../../build/jni-crypto'
environment RUSTFLAGS: "-L ${System.getenv('PTHREAD_LOCATION')}"
}
} else {
// keep the old build behavior while not running in nix shell
if (System.getProperty("os.name").toLowerCase().contains("linux")) {
exec {
workingDir 'src/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target=x86_64-unknown-linux-gnu', '--target-dir=../../build/jni-crypto'
}
} else if (System.getProperty("os.name").toLowerCase().contains("windows")) {
exec {
workingDir 'src/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target=x86_64-pc-windows-gnu', '--target-dir=../../build/jni-crypto'
}
}
// Does not cover solaris, just MacOS. See potential return types here:
// https://docs.gradle.org/current/javadoc/org/gradle/nativeplatform/platform/OperatingSystem.html
else {
exec {
workingDir 'src/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target-dir=../../build/jni-crypto'
}
}
}
}
Expand All @@ -44,7 +61,11 @@ processResources {
include '*.dylib'
}
from("${buildDir}/jni-crypto/x86_64-unknown-linux-gnu/release") {
into "include/linux"
into "include/x86_64-linux"
include '*.so'
}
from("${buildDir}/jni-crypto/aarch64-unknown-linux-gnu/release") {
into "include/aarch64-linux"
include '*.so'
}
from("${buildDir}/jni-crypto/x86_64-pc-windows-gnu/release") {
Expand Down
3 changes: 2 additions & 1 deletion crypto/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// TODO write readme.md :)
Preparation:
`rustup target add x86_64-pc-windows-gnu`
`sudo apt install gcc-mingw-w64-x86-64`
`rustup target add aarch64-unknown-linux-gnu`
`sudo apt install gcc-mingw-w64-x86-64`
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ class Native {
private static final String LIB_PATH = "SUBSTRATE_CLIENT_CRYPTO_LIB_PATH";
private static final String LIB_NAME = "jni_crypto";
private static final String OS_NAME = System.getProperty("os.name").toLowerCase();
private static final String ARCH_NAME = System.getProperty("os.arch").toLowerCase();
private static final boolean IS_WINDOWS = OS_NAME.contains("win");
private static final boolean IS_MAC = OS_NAME.contains("mac");
private static final boolean IS_LINUX = OS_NAME.contains("linux");
private static final boolean IS_AMD64 = ARCH_NAME.contains("amd64") || ARCH_NAME.contains("x86_64");
private static final boolean IS_AARCH64 = ARCH_NAME.contains("aarch64");

static {
try {
Expand All @@ -49,9 +52,11 @@ private static String copyLibraryFromResourcesToTempDir() throws IOException {
String osDir;
if (IS_WINDOWS) {
osDir = "windows";
} else if (IS_LINUX) {
osDir = "linux";
} else if (IS_MAC) { // TODO 'MasOS support problem'
} else if (IS_LINUX && IS_AMD64) {
osDir = "x86_64-linux";
} else if (IS_LINUX && IS_AARCH64) {
osDir = "aarch64-linux";
} else if (IS_MAC) { // TODO 'MacOS support problem'
osDir = "macos";
} else {
throw new RuntimeException("JNI library can't be loaded because OS wasn't detected as supported.");
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
description = "Environment flake";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };

mkLinkerPath = {cc, ...}: "${cc}/bin/${cc.targetPrefix}cc";
in
{
devShells.default = with pkgs; mkShell {

CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = mkLinkerPath pkgsCross.aarch64-multiplatform.stdenv;
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER = mkLinkerPath pkgsCross.gnu64.stdenv;
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER = mkLinkerPath pkgsCross.mingwW64.stdenv;

# for mingw compilation
PTHREAD_LOCATION = "${pkgs.pkgsCross.mingwW64.windows.pthreads}/lib";

shellHook = "rustup show";

packages = [
temurin-bin-8
rustup
];
};
}
);
}
5 changes: 5 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[toolchain]
channel = "nightly-2024-02-04"
components = [ "rustc" ]
targets = [ "x86_64-pc-windows-gnu", "aarch64-unknown-linux-gnu", "x86_64-pc-windows-gnu" ]
profile = "minimal"

0 comments on commit a697b0f

Please sign in to comment.