瀏覽代碼

feat: support 3 more platforms

LongYinan 4 年之前
父節點
當前提交
cd8eb7ffc4

+ 6 - 2
.cargo/config.toml

@@ -1,11 +1,15 @@
 [target.aarch64-unknown-linux-gnu]
-linker = "aarch64-linux-gnu-gcc-10"
+linker = "aarch64-linux-gnu-gcc"
 
 [target.armv7-unknown-linux-gnueabihf]
-linker = "arm-linux-gnueabihf-gcc-10"
+linker = "arm-linux-gnueabihf-gcc"
 
 [target.x86_64-unknown-linux-musl]
 rustflags = [
   "-C",
   "target-feature=-crt-static",
 ]
+
+[target.aarch64-unknown-linux-musl]
+linker = "aarch64-linux-gnu-gcc"
+rustflags = ["-C", "target-feature=-crt-static", "-C", "link-arg=-lgcc"]

+ 60 - 3
.github/workflows/CI.yaml

@@ -58,18 +58,27 @@ jobs:
           - host: ubuntu-20.04
             target: 'aarch64-unknown-linux-gnu'
             setup: |
-              sudo apt-get install g++-10-aarch64-linux-gnu gcc-10-aarch64-linux-gnu -y
+              sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y
             build: yarn build --target=aarch64-unknown-linux-gnu
           - host: ubuntu-20.04
             target: 'armv7-unknown-linux-gnueabihf'
             setup: |
-              sudo apt-get install gcc-10-arm-linux-gnueabihf g++-10-arm-linux-gnueabihf -y
+              sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
             build: yarn build --target=armv7-unknown-linux-gnueabihf
           - host: ubuntu-20.04
             target: 'aarch64-linux-android'
             build: |
               export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
               yarn build --target aarch64-linux-android
+          - host: ubuntu-latest
+            target: 'aarch64-unknown-linux-musl'
+            setup: |
+              sudo apt-get update
+              sudo apt-get install gcc-aarch64-linux-gnu -y
+            build: yarn build --target aarch64-unknown-linux-musl
+          - host: windows-latest
+            target: 'aarch64-pc-windows-msvc'
+            build: yarn build --target aarch64-pc-windows-msvc
 
     name: stable - ${{ matrix.settings.target }} - node@14
     runs-on: ${{ matrix.settings.host }}
@@ -140,6 +149,53 @@ jobs:
           name: bindings-${{ matrix.settings.target }}
           path: ${{ env.APP_NAME }}.*.node
 
+  build-freebsd:
+    runs-on: macos-latest
+    name: Build FreeBSD
+    steps:
+      - uses: actions/checkout@v2
+      - name: Build
+        id: build
+        uses: vmactions/freebsd-vm@v0.1.4
+        env:
+          DEBUG: 'napi:*'
+          RUSTUP_HOME: /usr/local/rustup
+          CARGO_HOME: /usr/local/cargo
+          RUSTUP_IO_THREADS: 1
+        with:
+          envs: 'DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS'
+          usesh: true
+          mem: 3000
+          prepare: |
+            pkg install -y curl node yarn npm python2
+            curl https://sh.rustup.rs -sSf --output rustup.sh
+            sh rustup.sh -y --profile minimal --default-toolchain stable
+            export PATH="/usr/local/cargo/bin:$PATH"
+            echo "~~~~ rustc --version ~~~~"
+            rustc --version
+            echo "~~~~ node -v ~~~~"
+            node -v
+            echo "~~~~ yarn --version ~~~~"
+            yarn --version
+          run: |
+            export PATH="/usr/local/cargo/bin:$PATH"
+            pwd
+            ls -lah
+            whoami
+            env
+            freebsd-version
+            yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
+            yarn build
+            yarn test
+            rm -rf node_modules
+            rm -rf target
+
+      - name: Upload artifact
+        uses: actions/upload-artifact@v2
+        with:
+          name: bindings-freebsd
+          path: ${{ env.APP_NAME }}.*.node
+
   test-macOS-windows-binding:
     name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
     needs:
@@ -379,6 +435,7 @@ jobs:
       - test-linux-aarch64-gnu-binding
       - test-linux-arm-gnueabihf-binding
       - test-macOS-windows-binding
+      - build-freebsd
 
     steps:
       - uses: actions/checkout@v2
@@ -408,7 +465,7 @@ jobs:
         run: yarn artifacts
 
       - name: List packages
-        run: ls -R .
+        run: ls -R ./npm
         shell: bash
 
       - name: Publish

+ 18 - 13
README.md

@@ -14,21 +14,26 @@ yarn add @napi-rs/package-template
 
 ### Operating Systems
 
-| Linux x64/aarch64 | macOS x64/aarch64 | Windows x64 |
-| ----------------- | ----------------- | ----------- |
-| ✓                 | ✓                 | ✓           |
-
-### NodeJS
-
-| Node10 | Node 12 | Node14 | Node15 |
-| ------ | ------- | ------ | ------ |
-| ✓      | ✓       | ✓      | ✓      |
+|                  | node12 | node14 | node16 |
+| ---------------- | ------ | ------ | ------ |
+| Windows x64      | ✓      | ✓      | ✓      |
+| Windows x32      | ✓      | ✓      | ✓      |
+| Windows arm64    | ✓      | ✓      | ✓      |
+| macOS x64        | ✓      | ✓      | ✓      |
+| macOS arm64      | ✓      | ✓      | ✓      |
+| Linux x64 gnu    | ✓      | ✓      | ✓      |
+| Linux x64 musl   | ✓      | ✓      | ✓      |
+| Linux arm gnu    | ✓      | ✓      | ✓      |
+| Linux arm64 gnu  | ✓      | ✓      | ✓      |
+| Linux arm64 musl | ✓      | ✓      | ✓      |
+| Android arm64    | ✓      | ✓      | ✓      |
+| FreeBSD x64      | ✓      | ✓      | ✓      |
 
 ## Ability
 
 ### Build
 
-After `yarn build/npm run build` command, you can see `index.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs).
+After `yarn build/npm run build` command, you can see `package-template.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs).
 
 ### Test
 
@@ -36,11 +41,11 @@ With [ava](https://github.com/avajs/ava), run `yarn test/npm run test` to testin
 
 ### CI
 
-With github actions, every commits and pull request will be built and tested automatically in [`node@10`, `node@12`, `@node14`] x [`macOS`, `Linux`, `Windows`] matrix. You will never be afraid of the native addon broken in these platforms.
+With github actions, every commits and pull request will be built and tested automatically in [`node@12`, `node@14`, `@node16`] x [`macOS`, `Linux`, `Windows`] matrix. You will never be afraid of the native addon broken in these platforms.
 
 ### Release
 
-Release native package is very difficult in old days. Native packages may ask developers who use its to install `build toolchains` like `gcc/llvm` , `node-gyp` or something more.
+Release native package is very difficult in old days. Native packages may ask developers who use its to install `build toolchain` like `gcc/llvm` , `node-gyp` or something more.
 
 With `Github actions`, we can easily prebuild `binary` for major platforms. And with `N-API`, we should never afraid of **ABI Compatible**.
 
@@ -53,7 +58,7 @@ In this package we choose a better way to solve this problem. We release differe
 ## Develop requirements
 
 - Install latest `Rust`
-- Install `NodeJS@10+` which fully supported `N-API`
+- Install `Node.js@10+` which fully supported `Node-API`
 - Install `yarn@1.x`
 
 ## Test in local

+ 3 - 0
npm/freebsd-x64/README.md

@@ -0,0 +1,3 @@
+# `@napi-rs/package-template-freebsd-x64`
+
+This is the **x86_64-unknown-freebsd** binary for `@napi-rs/package-template`

+ 19 - 0
npm/freebsd-x64/package.json

@@ -0,0 +1,19 @@
+{
+  "name": "@napi-rs/package-template-freebsd-x64",
+  "version": "1.0.0",
+  "os": ["freebsd"],
+  "cpu": ["x64"],
+  "main": "package-template.freebsd-x64.node",
+  "files": ["package-template.freebsd-x64.node"],
+  "description": "Template project for writing node package with napi-rs",
+  "keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
+  "license": "MIT",
+  "engines": {
+    "node": ">= 10"
+  },
+  "publishConfig": {
+    "registry": "https://registry.npmjs.org/",
+    "access": "public"
+  },
+  "repository": "git@github.com:napi-rs/package-template.git"
+}

+ 3 - 0
npm/linux-arm64-musl/README.md

@@ -0,0 +1,3 @@
+# `@napi-rs/package-template-linux-arm64-musl`
+
+This is the **aarch64-unknown-linux-musl** binary for `@napi-rs/package-template`

+ 19 - 0
npm/linux-arm64-musl/package.json

@@ -0,0 +1,19 @@
+{
+  "name": "@napi-rs/package-template-linux-arm64-musl",
+  "version": "1.0.0",
+  "os": ["linux"],
+  "cpu": ["arm64"],
+  "main": "package-template.linux-arm64-musl.node",
+  "files": ["package-template.linux-arm64-musl.node"],
+  "description": "Template project for writing node package with napi-rs",
+  "keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
+  "license": "MIT",
+  "engines": {
+    "node": ">= 10"
+  },
+  "publishConfig": {
+    "registry": "https://registry.npmjs.org/",
+    "access": "public"
+  },
+  "repository": "git@github.com:napi-rs/package-template.git"
+}

+ 3 - 0
npm/win32-arm64-msvc/README.md

@@ -0,0 +1,3 @@
+# `@napi-rs/package-template-win32-arm64-msvc`
+
+This is the **aarch64-pc-windows-msvc** binary for `@napi-rs/package-template`

+ 19 - 0
npm/win32-arm64-msvc/package.json

@@ -0,0 +1,19 @@
+{
+  "name": "@napi-rs/package-template-win32-arm64-msvc",
+  "version": "1.0.0",
+  "os": ["win32"],
+  "cpu": ["arm64"],
+  "main": "package-template.win32-arm64-msvc.node",
+  "files": ["package-template.win32-arm64-msvc.node"],
+  "description": "Template project for writing node package with napi-rs",
+  "keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
+  "license": "MIT",
+  "engines": {
+    "node": ">= 10"
+  },
+  "publishConfig": {
+    "registry": "https://registry.npmjs.org/",
+    "access": "public"
+  },
+  "repository": "git@github.com:napi-rs/package-template.git"
+}

+ 7 - 4
package.json

@@ -17,7 +17,10 @@
         "i686-pc-windows-msvc",
         "armv7-unknown-linux-gnueabihf",
         "aarch64-apple-darwin",
-        "aarch64-linux-android"
+        "aarch64-linux-android",
+        "x86_64-unknown-freebsd",
+        "aarch64-unknown-linux-musl",
+        "aarch64-pc-windows-msvc"
       ]
     }
   },
@@ -47,8 +50,8 @@
   "devDependencies": {
     "@napi-rs/cli": "^1.0.4",
     "@swc-node/register": "^1.3.1",
-    "@typescript-eslint/eslint-plugin": "^4.25.0",
-    "@typescript-eslint/parser": "^4.25.0",
+    "@typescript-eslint/eslint-plugin": "^4.26.0",
+    "@typescript-eslint/parser": "^4.26.0",
     "ava": "^3.15.0",
     "benny": "^3.6.15",
     "chalk": "^4.1.1",
@@ -64,7 +67,7 @@
     "typescript": "^4.3.2"
   },
   "dependencies": {
-    "@node-rs/helper": "^1.1.0"
+    "@node-rs/helper": "^1.1.1"
   },
   "lint-staged": {
     "*.@(js|ts|tsx)": ["prettier --write", "eslint -c .eslintrc.yml --fix"],

文件差異過大導致無法顯示
+ 307 - 298
yarn.lock