Skip to content

Commit aa84375

Browse files
Added git action to publish npm package @netapplabs/nfs-js-node
1 parent 5eed317 commit aa84375

File tree

18 files changed

+420
-128
lines changed

18 files changed

+420
-128
lines changed

.cargo/config.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
[target.aarch64-unknown-linux-gnu]
22
linker = "aarch64-linux-gnu-gcc"
3+
rustflags = ["-C", "link-arg=-Wl,-rpath,$ORIGIN/lib/linux/arm64/gnu"]
4+
5+
[target.x86_64-unknown-linux-gnu]
6+
linker = "x86_64-linux-gnu-gcc"
7+
rustflags = ["-C", "link-arg=-Wl,-rpath,$ORIGIN/lib/linux/x64/gnu"]
38

49
[target.armv7-unknown-linux-gnueabihf]
510
linker = "arm-linux-gnueabihf-gcc"
@@ -11,3 +16,9 @@ rustflags = ["-C", "target-feature=-crt-static"]
1116
[target.aarch64-unknown-linux-musl]
1217
linker = "aarch64-linux-musl-gcc"
1318
rustflags = ["-C", "target-feature=-crt-static"]
19+
20+
[target.aarch64-apple-darwin]
21+
rustflags = [ "-Clink-args=-Wl,-rpath,@loader_path/lib/darwin/arm64" ]
22+
23+
[target.x86_64-apple-darwin]
24+
rustflags = [ "-Clink-args=-Wl,-rpath,@loader_path/lib/darwin/x64" ]

.github/workflows/node.js.yml

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
11
# 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
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
33

4-
name: Node.js CI
4+
name: CI
55

66
on:
77
push:
8-
branches: [ "master", "fridvin*" ]
8+
branches: [ "*" ]
99
pull_request:
10-
branches: [ "master", "fridvin*" ]
10+
branches: [ "*" ]
1111

1212
env:
1313
CARGO_TERM_COLOR: always
1414

1515
jobs:
1616
build:
17-
18-
runs-on: ${{ matrix.os }}
19-
17+
runs-on: ${{ matrix.settings.host }}
2018
permissions:
2119
contents: write
2220
packages: write
23-
2421
strategy:
2522
matrix:
26-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
27-
node-version: [ 18.x ]
28-
os: [ macos-latest, ubuntu-latest ]
29-
23+
settings:
24+
- host: ubuntu-22.04
25+
target: x86_64-unknown-linux-gnu
26+
runtests: true
27+
- host: ubuntu-22.04
28+
target: aarch64-unknown-linux-gnu
29+
runtests: false
30+
- host: macos-latest
31+
target: aarch64-apple-darwin
32+
runtests: true
33+
- host: macos-latest
34+
target: x86_64-apple-darwin
35+
runtests: false
3036
steps:
31-
- uses: actions/checkout@v3
37+
- uses: actions/checkout@v4
3238
- name: Setup go
3339
uses: actions/setup-go@v3
3440
with:
@@ -50,21 +56,76 @@ jobs:
5056
ln -sf $HOME/.ssh/nfs-rs $HOME/.ssh/id_rsa
5157
git clone git@github.com:NetAppLabs/nfs-rs.git
5258
rm $HOME/.ssh/id_rsa
53-
- name: Install non-rust non-node dependencies
54-
run: ./deps.sh
55-
- name: Use Node.js ${{ matrix.node-version }}
56-
uses: actions/setup-node@v3
59+
- name: linux deps
60+
if: runner.os == 'Linux'
61+
shell: bash
62+
run: |
63+
sudo apt-get -y install \
64+
libc6-dev-amd64-cross libc6-dev-arm64-cross \
65+
crossbuild-essential-arm64 crossbuild-essential-amd64 \
66+
gcc-aarch64-linux-gnu \
67+
binfmt-support binutils binutils-aarch64-linux-gnu
68+
- uses: mlugg/setup-zig@v1
69+
- uses: actions-rust-lang/setup-rust-toolchain@v1
5770
with:
58-
node-version: ${{ matrix.node-version }}
71+
rustflags: ""
72+
- name: Use Node.js
73+
uses: actions/setup-node@v4
74+
with:
75+
node-version: 20.x
5976
cache: 'yarn'
77+
registry-url: 'https://npm.pkg.github.com'
78+
scope: '@netapplabs'
6079
- name: Prepare yarn
61-
run: yarn install --immutable
80+
run: yarn install
6281
- name: Build
63-
run: yarn build
82+
run: yarn build --target ${{ matrix.settings.target }}
6483
- name: Test
84+
if: ${{ matrix.settings.runtests }}
6585
run: yarn test
6686
- name: Upload node module
6787
uses: actions/upload-artifact@v4
6888
with:
69-
name: nfs-js.${{ matrix.os }}-x64-node${{ matrix.node-version }}.node
70-
path: nfs-js.*.node
89+
name: nfs-js-node.${{ matrix.settings.host }}-${{ matrix.settings.target }}
90+
path: |
91+
nfs-js-node.*.node
92+
lib
93+
publish:
94+
runs-on: ubuntu-22.04
95+
if: ${{ github.ref == 'refs/heads/master' }}
96+
permissions:
97+
contents: write
98+
packages: write
99+
needs: build
100+
steps:
101+
- uses: actions/checkout@v4
102+
- name: Use Node.js
103+
uses: actions/setup-node@v4
104+
with:
105+
node-version: 20.x
106+
cache: 'yarn'
107+
registry-url: 'https://npm.pkg.github.com'
108+
scope: '@netapplabs'
109+
110+
- name: Download Artifact
111+
uses: actions/download-artifact@v4
112+
with:
113+
pattern: nfs-js-node.*
114+
merge-multiple: true
115+
116+
- name: Setup git
117+
run: |
118+
git config --global user.name 'github-actions[bot]'
119+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
120+
121+
- name: Bump version
122+
run: npx standard-version
123+
124+
- name: Publish Artifacts
125+
run: npm publish --ignore-scripts
126+
env:
127+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
128+
129+
- name: Commit and push version bump
130+
run: |
131+
git push --follow-tags

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,5 @@ libnfs
132132

133133
npm
134134
.turbo
135+
lib
136+
krb5

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
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.

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
authors = ["LongYinan <lynweklm@gmail.com>","Tryggvi Larusson <Tryggvi.Larusson@netapp.com>","Fridvin Oddbjornsson <Fridvin.Oddbjornsson@netapp.com>"]
33
edition = "2021"
44
name = "nfs-js"
5-
version = "0.7.0"
5+
version = "0.8.0"
66

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

@@ -30,6 +30,7 @@ napi-build = "2"
3030

3131
[profile.release]
3232
lto = true
33+
rpath = true
3334

3435
[patch.crates-io]
3536
libnfs-sys = { path = "./libnfs-sys" }

__test__/index.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ ava_1.default.serial('should be same entry as self for directory', async (t) =>
6565
});
6666
ava_1.default.serial('should not be same entry as others for directory', async (t) => {
6767
const rootHandle = getRootHandle();
68-
const fileHandle = await rootHandle.getFileHandle('annar');
69-
const dirHandle = await rootHandle.getDirectoryHandle('first');
68+
const fileHandle = await rootHandle.getFileHandle('annar', {});
69+
const dirHandle = await rootHandle.getDirectoryHandle('first', {});
7070
t.false(await fileHandle.isSameEntry(dirHandle));
7171
t.false(await rootHandle.isSameEntry(dirHandle));
7272
t.false(await dirHandle.isSameEntry(fileHandle));
@@ -739,7 +739,7 @@ ava_1.default.serial('should return non-locked writable when creating writable a
739739
ava_1.default.serial('should return error when writing unsupported type', async (t) => {
740740
const rootHandle = getRootHandle();
741741
const fileHandle = await rootHandle.getFileHandle('writable-write-unsupported-type', { create: true });
742-
const writable = await fileHandle.createWritable();
742+
const writable = await fileHandle.createWritable({});
743743
const err = await t.throwsAsync(writable.write(69));
744744
t.is(err?.message, 'Writing unsupported type');
745745
await rootHandle.removeEntry(fileHandle.name);

__test__/index.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ test.serial('should be same entry as self for directory', async (t) => {
6868

6969
test.serial('should not be same entry as others for directory', async (t) => {
7070
const rootHandle = getRootHandle();
71-
const fileHandle = await rootHandle.getFileHandle('annar');
72-
const dirHandle = await rootHandle.getDirectoryHandle('first');
71+
const fileHandle = await rootHandle.getFileHandle('annar', {});
72+
const dirHandle = await rootHandle.getDirectoryHandle('first', {});
7373
t.false(await fileHandle.isSameEntry(dirHandle));
7474
t.false(await rootHandle.isSameEntry(dirHandle));
7575
t.false(await dirHandle.isSameEntry(fileHandle));
@@ -810,7 +810,7 @@ test.serial('should return non-locked writable when creating writable and keepin
810810
test.serial('should return error when writing unsupported type', async (t) => {
811811
const rootHandle = getRootHandle();
812812
const fileHandle = await rootHandle.getFileHandle('writable-write-unsupported-type', {create: true}) as NfsFileHandle;
813-
const writable = await fileHandle.createWritable();
813+
const writable = await fileHandle.createWritable({});
814814
const err = await t.throwsAsync(writable.write(69 as any));
815815
t.is(err?.message, 'Writing unsupported type');
816816
await rootHandle.removeEntry(fileHandle.name);

build.sh

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,75 @@
1616
# SPDX-License-Identifier: Apache-2.0
1717

1818

19-
set -e
19+
set -ex
2020

21-
./deps.sh
21+
ARG1="$1"
22+
23+
LOCAL_TARGET_TRIPLE=`rustc --version --verbose | grep ^host | awk -F ' ' '{print $2}'`
24+
TARGET_TRIPLE="${LOCAL_TARGET_TRIPLE}"
25+
26+
if [[ "${ARG1}" == "--target" ]]; then
27+
ARG2="$2"
28+
if [ -n "${ARG2}" ]; then
29+
TARGET_TRIPLE="${ARG2}"
30+
fi
31+
fi
32+
33+
rustup target add ${TARGET_TRIPLE}
34+
TARGET_TRIPLE_FOR_CC=`echo ${TARGET_TRIPLE} | sed 's/-unknown//g'`
35+
36+
if [[ "${TARGET_TRIPLE}" == *"linux"* ]]; then
37+
export BINDGEN_EXTRA_CLANG_ARGS="-I/usr/${TARGET_TRIPLE_FOR_CC}/include"
38+
elif [[ "${TARGET_TRIPLE}" == *"darwin"* ]]; then
39+
TARGET_TRIPLE_FOR_CC=`echo ${TARGET_TRIPLE} | sed 's/aarch64/arm64/g'`
40+
fi
41+
42+
./deps.sh ${TARGET_TRIPLE} ${TARGET_TRIPLE_FOR_CC}
2243

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

2546
LIBNFS_BASE="${SCRIPT_DIR}/libnfs"
26-
LIBNFS_BASE_INSTALL="${SCRIPT_DIR}/libnfs/local-install"
27-
export LIBNFS_LIB_PATH="${LIBNFS_BASE}/lib/.libs/"
47+
LIBNFS_BASE_INSTALL="${SCRIPT_DIR}/libnfs/local-install/${TARGET_TRIPLE}"
48+
49+
NODE_ARCH=`echo ${TARGET_TRIPLE} | awk -F '-' '{print $1}' | sed 's/aarch64/arm64/g' | sed 's/x86_64/x64/g'`
50+
NODE_PLATFORM=`echo ${TARGET_TRIPLE} | awk -F '-' '{print $2}'`
51+
NODE_OS=`echo ${TARGET_TRIPLE} | awk -F '-' '{print $3}'`
52+
NODE_OS_VARIANT=`echo ${TARGET_TRIPLE} | awk -F '-' '{print $4}'`
53+
54+
LIBNFS_BASE_LIB_INSTALL_PATH="${LIBNFS_BASE_INSTALL}/lib"
55+
56+
NFS_JS_LIB_FULL_VER=`cat ${LIBNFS_BASE_LIB_INSTALL_PATH}/pkgconfig/libnfs.pc | grep '^Version:' | awk '{print $2}'`
57+
NFS_JS_LIB_VER=`echo ${NFS_JS_LIB_FULL_VER} | awk -F '.' '{print $1}'`
58+
59+
export LIBNFS_LIB_PATH="./lib/${NODE_OS}/${NODE_ARCH}"
60+
if [ -n "${NODE_OS_VARIANT}" ]; then
61+
export LIBNFS_LIB_PATH="./lib/${NODE_OS}/${NODE_ARCH}/${NODE_OS_VARIANT}"
62+
fi
63+
mkdir -p ${LIBNFS_LIB_PATH}
64+
if [ "${NODE_OS}" == "darwin" ]; then
65+
cp -R ${LIBNFS_BASE_LIB_INSTALL_PATH}/libnfs.${NFS_JS_LIB_VER}.dylib ${LIBNFS_LIB_PATH}/
66+
cp -R ${LIBNFS_BASE_LIB_INSTALL_PATH}/libnfs.dylib ${LIBNFS_LIB_PATH}/
67+
elif [ "${NODE_OS}" == "linux" ]; then
68+
cp -R ${LIBNFS_BASE_LIB_INSTALL_PATH}/libnfs.so* ${LIBNFS_LIB_PATH}/
69+
fi
70+
2871
export LIBNFS_INCLUDE_PATH="${LIBNFS_BASE_INSTALL}/include"
2972

30-
export LIBNFS_LINK_STATIC="true"
73+
export LIBNFS_LINK_STATIC="false"
3174

3275
export DYLD_LIBRARY_PATH=${LIBNFS_LIB_PATH}:$DYLD_LIBRARY_PATH
3376
export LD_LIBRARY_PATH=${LIBNFS_LIB_PATH}:$LD_LIBRARY_PATH
3477

3578
export RUST_BACKTRACE=1
3679

37-
yarn build-napi
80+
if [ "$ARG1" == "test" ]; then
81+
cargo test --release
82+
else
83+
yarn build-tsc
84+
yarn build-napi --target ${TARGET_TRIPLE}
85+
fi
86+
87+
if [ "${NODE_OS}" == "darwin" ]; then
88+
# rewrite dylib search path after build for macos
89+
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
90+
fi

0 commit comments

Comments
 (0)