Skip to content
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
11 changes: 11 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
rustflags = ["-C", "link-arg=-Wl,-rpath,$ORIGIN/lib/linux/arm64/gnu"]

[target.x86_64-unknown-linux-gnu]
linker = "x86_64-linux-gnu-gcc"
rustflags = ["-C", "link-arg=-Wl,-rpath,$ORIGIN/lib/linux/x64/gnu"]

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
Expand All @@ -11,3 +16,9 @@ rustflags = ["-C", "target-feature=-crt-static"]
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"
rustflags = ["-C", "target-feature=-crt-static"]

[target.aarch64-apple-darwin]
rustflags = [ "-Clink-args=-Wl,-rpath,@loader_path/lib/darwin/arm64" ]

[target.x86_64-apple-darwin]
rustflags = [ "-Clink-args=-Wl,-rpath,@loader_path/lib/darwin/x64" ]
103 changes: 82 additions & 21 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI
name: CI

on:
push:
branches: [ "master", "fridvin*" ]
branches: [ "*" ]
pull_request:
branches: [ "master", "fridvin*" ]
branches: [ "*" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ${{ matrix.os }}

runs-on: ${{ matrix.settings.host }}
permissions:
contents: write
packages: write

strategy:
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [ 18.x ]
os: [ macos-latest, ubuntu-latest ]

settings:
- host: ubuntu-22.04
target: x86_64-unknown-linux-gnu
runtests: true
- host: ubuntu-22.04
target: aarch64-unknown-linux-gnu
runtests: false
- host: macos-latest
target: aarch64-apple-darwin
runtests: true
- host: macos-latest
target: x86_64-apple-darwin
runtests: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v3
with:
Expand All @@ -50,21 +56,76 @@ jobs:
ln -sf $HOME/.ssh/nfs-rs $HOME/.ssh/id_rsa
git clone [email protected]:NetAppLabs/nfs-rs.git
rm $HOME/.ssh/id_rsa
- name: Install non-rust non-node dependencies
run: ./deps.sh
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
- name: linux deps
if: runner.os == 'Linux'
shell: bash
run: |
sudo apt-get -y install \
libc6-dev-amd64-cross libc6-dev-arm64-cross \
crossbuild-essential-arm64 crossbuild-essential-amd64 \
gcc-aarch64-linux-gnu \
binfmt-support binutils binutils-aarch64-linux-gnu
- uses: mlugg/setup-zig@v1
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
node-version: ${{ matrix.node-version }}
rustflags: ""
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'yarn'
registry-url: 'https://npm.pkg.github.com'
scope: '@netapplabs'
- name: Prepare yarn
run: yarn install --immutable
run: yarn install
- name: Build
run: yarn build
run: yarn build --target ${{ matrix.settings.target }}
- name: Test
if: ${{ matrix.settings.runtests }}
run: yarn test
- name: Upload node module
uses: actions/upload-artifact@v4
with:
name: nfs-js.${{ matrix.os }}-x64-node${{ matrix.node-version }}.node
path: nfs-js.*.node
name: nfs-js-node.${{ matrix.settings.host }}-${{ matrix.settings.target }}
path: |
nfs-js-node.*.node
lib
publish:
runs-on: ubuntu-22.04
if: ${{ github.ref == 'refs/heads/master' }}
permissions:
contents: write
packages: write
needs: build
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'yarn'
registry-url: 'https://npm.pkg.github.com'
scope: '@netapplabs'

- name: Download Artifact
uses: actions/download-artifact@v4
with:
pattern: nfs-js-node.*
merge-multiple: true

- name: Setup git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

- name: Bump version
run: npx standard-version

- name: Publish Artifacts
run: npm publish --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Commit and push version bump
run: |
git push --follow-tags
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,5 @@ libnfs

npm
.turbo
lib
krb5
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
2 changes: 1 addition & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["LongYinan <[email protected]>","Tryggvi Larusson <[email protected]>","Fridvin Oddbjornsson <[email protected]>"]
edition = "2021"
name = "nfs-js"
version = "0.7.0"
version = "0.8.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down Expand Up @@ -30,6 +30,7 @@ napi-build = "2"

[profile.release]
lto = true
rpath = true

[patch.crates-io]
libnfs-sys = { path = "./libnfs-sys" }
6 changes: 3 additions & 3 deletions __test__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ ava_1.default.serial('should be same entry as self for directory', async (t) =>
});
ava_1.default.serial('should not be same entry as others for directory', async (t) => {
const rootHandle = getRootHandle();
const fileHandle = await rootHandle.getFileHandle('annar');
const dirHandle = await rootHandle.getDirectoryHandle('first');
const fileHandle = await rootHandle.getFileHandle('annar', {});
const dirHandle = await rootHandle.getDirectoryHandle('first', {});
t.false(await fileHandle.isSameEntry(dirHandle));
t.false(await rootHandle.isSameEntry(dirHandle));
t.false(await dirHandle.isSameEntry(fileHandle));
Expand Down Expand Up @@ -739,7 +739,7 @@ ava_1.default.serial('should return non-locked writable when creating writable a
ava_1.default.serial('should return error when writing unsupported type', async (t) => {
const rootHandle = getRootHandle();
const fileHandle = await rootHandle.getFileHandle('writable-write-unsupported-type', { create: true });
const writable = await fileHandle.createWritable();
const writable = await fileHandle.createWritable({});
const err = await t.throwsAsync(writable.write(69));
t.is(err?.message, 'Writing unsupported type');
await rootHandle.removeEntry(fileHandle.name);
Expand Down
6 changes: 3 additions & 3 deletions __test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ test.serial('should be same entry as self for directory', async (t) => {

test.serial('should not be same entry as others for directory', async (t) => {
const rootHandle = getRootHandle();
const fileHandle = await rootHandle.getFileHandle('annar');
const dirHandle = await rootHandle.getDirectoryHandle('first');
const fileHandle = await rootHandle.getFileHandle('annar', {});
const dirHandle = await rootHandle.getDirectoryHandle('first', {});
t.false(await fileHandle.isSameEntry(dirHandle));
t.false(await rootHandle.isSameEntry(dirHandle));
t.false(await dirHandle.isSameEntry(fileHandle));
Expand Down Expand Up @@ -810,7 +810,7 @@ test.serial('should return non-locked writable when creating writable and keepin
test.serial('should return error when writing unsupported type', async (t) => {
const rootHandle = getRootHandle();
const fileHandle = await rootHandle.getFileHandle('writable-write-unsupported-type', {create: true}) as NfsFileHandle;
const writable = await fileHandle.createWritable();
const writable = await fileHandle.createWritable({});
const err = await t.throwsAsync(writable.write(69 as any));
t.is(err?.message, 'Writing unsupported type');
await rootHandle.removeEntry(fileHandle.name);
Expand Down
65 changes: 59 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,75 @@
# SPDX-License-Identifier: Apache-2.0


set -e
set -ex

./deps.sh
ARG1="$1"

LOCAL_TARGET_TRIPLE=`rustc --version --verbose | grep ^host | awk -F ' ' '{print $2}'`
TARGET_TRIPLE="${LOCAL_TARGET_TRIPLE}"

if [[ "${ARG1}" == "--target" ]]; then
ARG2="$2"
if [ -n "${ARG2}" ]; then
TARGET_TRIPLE="${ARG2}"
fi
fi

rustup target add ${TARGET_TRIPLE}
TARGET_TRIPLE_FOR_CC=`echo ${TARGET_TRIPLE} | sed 's/-unknown//g'`

if [[ "${TARGET_TRIPLE}" == *"linux"* ]]; then
export BINDGEN_EXTRA_CLANG_ARGS="-I/usr/${TARGET_TRIPLE_FOR_CC}/include"
elif [[ "${TARGET_TRIPLE}" == *"darwin"* ]]; then
TARGET_TRIPLE_FOR_CC=`echo ${TARGET_TRIPLE} | sed 's/aarch64/arm64/g'`
fi

./deps.sh ${TARGET_TRIPLE} ${TARGET_TRIPLE_FOR_CC}

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

LIBNFS_BASE="${SCRIPT_DIR}/libnfs"
LIBNFS_BASE_INSTALL="${SCRIPT_DIR}/libnfs/local-install"
export LIBNFS_LIB_PATH="${LIBNFS_BASE}/lib/.libs/"
LIBNFS_BASE_INSTALL="${SCRIPT_DIR}/libnfs/local-install/${TARGET_TRIPLE}"

NODE_ARCH=`echo ${TARGET_TRIPLE} | awk -F '-' '{print $1}' | sed 's/aarch64/arm64/g' | sed 's/x86_64/x64/g'`
NODE_PLATFORM=`echo ${TARGET_TRIPLE} | awk -F '-' '{print $2}'`
NODE_OS=`echo ${TARGET_TRIPLE} | awk -F '-' '{print $3}'`
NODE_OS_VARIANT=`echo ${TARGET_TRIPLE} | awk -F '-' '{print $4}'`

LIBNFS_BASE_LIB_INSTALL_PATH="${LIBNFS_BASE_INSTALL}/lib"

NFS_JS_LIB_FULL_VER=`cat ${LIBNFS_BASE_LIB_INSTALL_PATH}/pkgconfig/libnfs.pc | grep '^Version:' | awk '{print $2}'`
NFS_JS_LIB_VER=`echo ${NFS_JS_LIB_FULL_VER} | awk -F '.' '{print $1}'`

export LIBNFS_LIB_PATH="./lib/${NODE_OS}/${NODE_ARCH}"
if [ -n "${NODE_OS_VARIANT}" ]; then
export LIBNFS_LIB_PATH="./lib/${NODE_OS}/${NODE_ARCH}/${NODE_OS_VARIANT}"
fi
mkdir -p ${LIBNFS_LIB_PATH}
if [ "${NODE_OS}" == "darwin" ]; then
cp -R ${LIBNFS_BASE_LIB_INSTALL_PATH}/libnfs.${NFS_JS_LIB_VER}.dylib ${LIBNFS_LIB_PATH}/
cp -R ${LIBNFS_BASE_LIB_INSTALL_PATH}/libnfs.dylib ${LIBNFS_LIB_PATH}/
elif [ "${NODE_OS}" == "linux" ]; then
cp -R ${LIBNFS_BASE_LIB_INSTALL_PATH}/libnfs.so* ${LIBNFS_LIB_PATH}/
fi

export LIBNFS_INCLUDE_PATH="${LIBNFS_BASE_INSTALL}/include"

export LIBNFS_LINK_STATIC="true"
export LIBNFS_LINK_STATIC="false"

export DYLD_LIBRARY_PATH=${LIBNFS_LIB_PATH}:$DYLD_LIBRARY_PATH
export LD_LIBRARY_PATH=${LIBNFS_LIB_PATH}:$LD_LIBRARY_PATH

export RUST_BACKTRACE=1

yarn build-napi
if [ "$ARG1" == "test" ]; then
cargo test --release
else
yarn build-tsc
yarn build-napi --target ${TARGET_TRIPLE}
fi

if [ "${NODE_OS}" == "darwin" ]; then
# rewrite dylib search path after build for macos
install_name_tool -change ${LIBNFS_BASE_LIB_INSTALL_PATH}/libnfs.${NFS_JS_LIB_VER}.dylib @loader_path/lib/${NODE_OS}/${NODE_ARCH}/libnfs.${NFS_JS_LIB_VER}.dylib nfs-js-node.${NODE_OS}-${NODE_ARCH}.node
fi
Loading
Loading