Skip to content

Commit

Permalink
Added aarch64 linux target and allow multi-architecture support (#180)
Browse files Browse the repository at this point in the history
# Goal
Allow using the the same Jar or node packages for different OS and
Architectures

Closes <!-- issue # -->
#155 #154 

# Changes
-Adds support of following operating systems and architectures for `Jar`
and `Node` packages
  - `Linux x86_64`
  - `Linux aarch64`
  - `MacOs x86_64`
  - `MacOs aarch64`
  -  `Windows x86_64`
- using `production` profile to generate size optimized binaries
  • Loading branch information
aramikm authored Mar 11, 2024
1 parent d28f428 commit 43dabf5
Show file tree
Hide file tree
Showing 13 changed files with 437 additions and 178 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/pr-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Install Rust Toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af
with:
toolchain: nightly-2024-03-01
toolchain: nightly-2023-12-28
default: true
profile: default
target: wasm32-unknown-unknown
Expand Down Expand Up @@ -133,10 +133,9 @@ jobs:
- name: Install Rust Toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af
with:
toolchain: stable
toolchain: nightly
default: true
profile: minimal
target: wasm32-unknown-unknown
- name: Install libsodium
run: sudo apt-get install -y libsodium-dev
- name: Run tests for ffi
Expand Down
113 changes: 81 additions & 32 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Install Rust Toolchain Nightly
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af
with:
toolchain: nightly-2024-03-01
toolchain: nightly-2023-12-28
default: false
profile: default
target: wasm32-unknown-unknown
Expand Down Expand Up @@ -73,12 +73,16 @@ jobs:
- os: ubuntu-latest
java_library: libdsnp_graph_sdk_jni.so
node_library: libdsnp_graph_sdk_node.so
rust-target: x86_64-unknown-linux-gnu
additional-rust-target: aarch64-unknown-linux-gnu
- os: windows-latest
java_library: dsnp_graph_sdk_jni.dll
node_library: dsnp_graph_sdk_node.dll
rust-target: x86_64-pc-windows-msvc
- os: macos-latest
java_library: libdsnp_graph_sdk_jni.dylib
node_library: libdsnp_graph_sdk_node.dylib
rust-target: x86_64-apple-darwin
additional-rust-target: aarch64-apple-darwin

name: Build project in ${{ matrix.os }}
Expand All @@ -93,10 +97,10 @@ jobs:
- name: Install Rust Toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af
with:
toolchain: stable
toolchain: nightly
default: true
profile: minimal
target: wasm32-unknown-unknown
target: ${{ matrix.rust-target }}

- run: rustup target add ${{ matrix.additional-rust-target }}
if: ${{ matrix.additional-rust-target != '' }}
Expand All @@ -114,40 +118,56 @@ jobs:
registry-url: https://registry.npmjs.org/

- name: Build Jni bridge
run: make build-jni
run: |
cargo build -p dsnp-graph-sdk-jni --profile production --target ${{ matrix.rust-target }}
mkdir -p artifacts/java
cp target/${{ matrix.rust-target }}/production/${{ matrix.java_library }} artifacts/java/${{ matrix.rust-target }}_${{ matrix.java_library }}
- name: Build Node bridge
run: make build-node
run: |
cargo build -p dsnp-graph-sdk-node --profile production --target ${{ matrix.rust-target }}
mkdir -p artifacts/node
cp target/${{ matrix.rust-target }}/production/${{ matrix.node_library }} artifacts/node/${{ matrix.rust-target }}_dsnp_graph_sdk_node.node
- name: Copy artifacts
- name: Build additional target for MacOS Jni
run: |
mkdir artifacts
cp target/release/${{ matrix.java_library }} artifacts/${{ matrix.java_library }}
cp target/release/${{ matrix.node_library }} artifacts/${{ matrix.node_library }}
cargo build -p dsnp-graph-sdk-jni --profile production --target ${{ matrix.additional-rust-target }}
mkdir -p artifacts/java
cp target/${{ matrix.additional-rust-target }}/production/${{ matrix.java_library }} artifacts/java/${{ matrix.additional-rust-target }}_${{ matrix.java_library }}
if: matrix.os == 'macos-latest' && matrix.additional-rust-target != ''

- name: Build Universal Binary for MacOS Jni
- name: Build additional target for MacOS Node
run: |
cargo build -p dsnp-graph-sdk-jni --profile release --target ${{ matrix.additional-rust-target }}
lipo -create -output artifacts/${{ matrix.java_library }} target/${{ matrix.additional-rust-target }}/release/${{ matrix.java_library }} target/release/${{ matrix.java_library }}
if: matrix.os == 'macos-latest'
cargo build -p dsnp-graph-sdk-node --profile production --target ${{ matrix.additional-rust-target }}
cp target/${{ matrix.additional-rust-target }}/production/${{ matrix.node_library }} artifacts/node/${{ matrix.additional-rust-target }}_dsnp_graph_sdk_node.node
if: matrix.os == 'macos-latest' && matrix.additional-rust-target != ''

- name: Build Universal Binary for MacOS Node
- name: Build additional targets for Linux Jni
run: |
cargo build -p dsnp-graph-sdk-node --profile release --target ${{ matrix.additional-rust-target }}
lipo -create -output artifacts/${{ matrix.node_library }} target/${{ matrix.additional-rust-target }}/release/${{ matrix.node_library }} target/release/${{ matrix.node_library }}
if: matrix.os == 'macos-latest'
cargo install cross
cross build +nightly --target ${{ matrix.additional-rust-target }} -p dsnp-graph-sdk-jni --profile production
cp target/${{ matrix.additional-rust-target }}/production/${{ matrix.java_library }} artifacts/java/${{ matrix.additional-rust-target }}_${{ matrix.java_library }}
if: matrix.os == 'ubuntu-latest' && matrix.additional-rust-target != ''

- name: Build with Gradle
working-directory: java
run: ./gradlew build
- name: Build other targets Binary for Linux Node
run: |
cross build +nightly --target ${{ matrix.additional-rust-target }} -p dsnp-graph-sdk-node --profile production
cp target/${{ matrix.additional-rust-target }}/production/${{ matrix.node_library }} artifacts/node/${{ matrix.additional-rust-target }}_dsnp_graph_sdk_node.node
if: matrix.os == 'ubuntu-latest' && matrix.additional-rust-target != ''

- name: Upload Artifacts Java
uses: actions/upload-artifact@v3
with:
name: artifacts-java-${{github.run_id}}
path: artifacts/java/

- name: Upload Artifacts
- name: Upload Artifacts Node
uses: actions/upload-artifact@v3
with:
name: artifacts-${{github.run_id}}
path: |
artifacts/${{ matrix.java_library }}
artifacts/${{ matrix.node_library }}
name: artifacts-node-${{github.run_id}}
path: artifacts/node/


publish-java:
name: Build and Publish JVM
Expand All @@ -163,8 +183,17 @@ jobs:
with:
java-version: '17'
distribution: 'adopt'
- name: Build JNI package
run: make build-jni
- name: Download Binaries
id: download-binaries
uses: actions/download-artifact@v3
with:
name: artifacts-java-${{github.run_id}}
path: java/lib/src/main/resources
- name: List Downloaded Binaries
run: |
download_dir=${{steps.download-binaries.outputs.download-path}}
echo "Download dir: $download_dir"
echo "Downloaded binaries: $(ls -l $download_dir)"
- name: Get current version
id: version
run: |
Expand Down Expand Up @@ -224,7 +253,21 @@ jobs:

- name: Build NPM Package
working-directory: bridge/node
run: npm run native:build-release && cp README.md dist/README.md
run: |
npm run tsc && cp README.md dist/README.md
- name: Download Binaries
id: download-binaries
uses: actions/download-artifact@v3
with:
name: artifacts-node-${{github.run_id}}
path: bridge/node

- name: Copy binaries
working-directory: bridge/node
run: |
cp *_dsnp_graph_sdk_node.node js/
cp *_dsnp_graph_sdk_node.node dist/js/
- name: Publish NPM Package
working-directory: bridge/node
Expand Down Expand Up @@ -293,15 +336,21 @@ jobs:
contents: write
packages: write
steps:
- name: Download Binaries
id: download-binaries
- name: Download Java Binaries
id: download-binaries-java
uses: actions/download-artifact@v3
with:
name: artifacts-${{github.run_id}}
name: artifacts-java-${{github.run_id}}
path: downloaded
- name: Download Java Binaries
id: download-binaries-node
uses: actions/download-artifact@v3
with:
name: artifacts-node-${{github.run_id}}
path: downloaded
- name: List Downloaded Binaries
run: |
download_dir=${{steps.download-binaries.outputs.download-path}}
download_dir=${{steps.download-binaries-node.outputs.download-path}}
echo "Download dir: $download_dir"
echo "Downloaded binaries: $(ls -l $download_dir)"
ls -R
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ inherits = "release"
lto = true
codegen-units = 1
strip = true
opt-level = "z"
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DEFAULT_GOAL := all

PROFILE := release
PROFILE := production

# Determine the operating system
UNAME := $(shell uname)
Expand Down Expand Up @@ -35,10 +35,10 @@ deny:
.PHONY: format
format:
@echo "Running Cargo fmt..."
@cargo +nightly-2024-03-01 fmt --all
@cargo +nightly-2023-12-28 fmt --all
format-check:
@echo "Running Cargo fmt..."
@cargo +nightly-2024-03-01 fmt --all -- --check
@cargo +nightly-2023-12-28 fmt --all -- --check

.PHONY: build
build:
Expand Down
2 changes: 1 addition & 1 deletion bridge/ffi/src/c_example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CC := gcc
CXX := g++
CFLAGS :=

PROFILE := release
PROFILE := production

# Linker options
LDFLAGS := -L../../../../target/$(PROFILE:dev=debug)
Expand Down
15 changes: 10 additions & 5 deletions bridge/node/js/graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,12 @@ describe("Graph tests", () => {
keys: [
{
index: 0,
content:Uint8Array.from(Buffer.from('40e3b18e1aa5c84175ec0c516838fb89dd9c947dd348fa38fe2082764bbc82a86f', 'hex')),
content: Uint8Array.from(
Buffer.from(
"40e3b18e1aa5c84175ec0c516838fb89dd9c947dd348fa38fe2082764bbc82a86f",
"hex",
),
),
},
] as KeyData[],
} as DsnpKeys;
Expand All @@ -529,18 +534,18 @@ describe("Graph tests", () => {

const imported = graph.importUserData([importBundle]);
expect(imported).toEqual(true);
let connectionPrivate: Connection = {
const connectionPrivate: Connection = {
dsnpUserId: "1000",
schemaId: 3,
};

let privateConnectAction: ConnectAction ={
const privateConnectAction: ConnectAction = {
type: "Connect",
ownerDsnpUserId: "1000",
dsnpKeys,
connection: connectionPrivate,
}
const appliedAction = await graph.applyActions([privateConnectAction]);
};
const appliedAction = await graph.applyActions([privateConnectAction]);
expect(appliedAction).toEqual(true);
const exported = graph.exportUpdates();
expect(exported).toBeDefined();
Expand Down
43 changes: 41 additions & 2 deletions bridge/node/js/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import path from "path";
import os from "os";
import fs from "fs";
import {
Action,
ActionOptions,
Expand All @@ -18,14 +20,51 @@ import {
// Load the native neon graphsdk module
function loadNativeModule(): Native {
try {
return require(path.join(__dirname, "/dsnp_graph_sdk_node.node"));
const targetPath = path.join(
__dirname,
`/${getTarget()}_dsnp_graph_sdk_node.node`,
);
if (fs.existsSync(targetPath)) {
return require(targetPath);
}else {
// using the default library name (useful for local testing)
return require(path.join(__dirname, "/dsnp_graph_sdk_node.node"));
}
} catch (error) {
let message = 'Unknown Error'
if (error instanceof Error) message = error.message
throw new Error(
"Unable to load the native module dsnp_graph_sdk_node.node",
`Unable to load the native module dsnp_graph_sdk_node.node (${message})`,
);
}
}

function getTarget(): String {
const platform = os.platform().toLowerCase();
const arch = os.arch().toLowerCase();

// Windows
if (platform.includes("win") && arch.includes("x64")) {
return "x86_64-pc-windows-msvc";

// MacOS
} else if (platform.includes("darwin") && arch.includes("x64")) {
return "x86_64-apple-darwin";
} else if (platform.includes("darwin") && arch.includes("arm64")) {
return "aarch64-apple-darwin";

// Linux
} else if (platform.includes("linux") && arch.includes("x64")) {
return "x86_64-unknown-linux-gnu";
} else if (platform.includes("linux") && arch.includes("arm64")) {
return "aarch64-unknown-linux-gnu";
}

throw new Error(
`Operating System: ${platform} Architecture: ${arch} is not supported!`,
);
}

// Define the Native interface
export interface Native {
printHelloGraph(): void;
Expand Down
Loading

0 comments on commit 43dabf5

Please sign in to comment.