Skip to content

Commit

Permalink
Attempt to build aarch64 so files
Browse files Browse the repository at this point in the history
  • Loading branch information
kczulko committed Mar 12, 2024
1 parent 66c43c5 commit c1de0b8
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 40 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/deploy-javadoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ jobs:

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

- 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
19 changes: 9 additions & 10 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
name: Gradle Build

on:
push
workflow_dispatch:
# push

jobs:
build:
Expand All @@ -15,14 +16,12 @@ 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
with:
java-version: '8'
distribution: 'temurin'

- 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 }}

15 changes: 3 additions & 12 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,10 @@ jobs:

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

- 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 --command bash -c "./gradlew build && ./gradlew publishToMavenLocal"
env:
USERNAME: ${{ github.actor }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
23 changes: 15 additions & 8 deletions crypto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ 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').empty) {
exec {
workingDir 'src/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target=aarch64-unknown-linux-gnu', '--target-dir=../../build/jni-crypto'
}
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'
environment RUSTFLAGS: "-L ${System.getenv('PTHREAD_LOCATION')}"
}
}
// Does not cover solaris, just MacOS. See potential return types here:
// https://docs.gradle.org/current/javadoc/org/gradle/nativeplatform/platform/OperatingSystem.html
else {
} else {
// Does not cover solaris, just MacOS. See potential return types here:
// https://docs.gradle.org/current/javadoc/org/gradle/nativeplatform/platform/OperatingSystem.html
exec {
workingDir 'src/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target-dir=../../build/jni-crypto'
Expand All @@ -44,7 +47,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,8 +52,10 @@ private static String copyLibraryFromResourcesToTempDir() throws IOException {
String osDir;
if (IS_WINDOWS) {
osDir = "windows";
} else if (IS_LINUX) {
osDir = "linux";
} else if (IS_LINUX && IS_AMD64) {
osDir = "x86_64-linux";
} else if (IS_LINUX && IS_AARCH64) {
osDir = "aarch64-linux";
} else if (IS_MAC) { // TODO 'MasOS support problem'
osDir = "macos";
} else {
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.

40 changes: 40 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
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, ...}:
# let
# inherit (stdenv) cc;
# in
"${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 c1de0b8

Please sign in to comment.