Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add riscv64gc-unknown-linux-gnu #947

Merged
merged 3 commits into from
Nov 19, 2024
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
31 changes: 20 additions & 11 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ jobs:
export CXX=aarch64-linux-android24-clang++
export CMAKE_TOOLCHAIN_FILE_aarch64_linux_android="$(pwd)/cmake/android-determine.cmake"
yarn build --target aarch64-linux-android
- host: ubuntu-latest
target: 'riscv64gc-unknown-linux-gnu'
downloadTarget: 'riscv64gc-unknown-linux-gnu'
build: |
sudo apt-get update
sudo apt-get install gcc-riscv64-linux-gnu g++-riscv64-linux-gnu -y
export CC=riscv64-linux-gnu-gcc
export CXX=riscv64-linux-gnu-g++
yarn build --target riscv64gc-unknown-linux-gnu

name: stable - ${{ matrix.settings.target }} - node@20
runs-on: ${{ matrix.settings.host }}
Expand Down Expand Up @@ -231,13 +240,13 @@ jobs:
fail-fast: false
matrix:
settings:
- host: macos-14
- host: macos-latest
target: 'x86_64-apple-darwin'
- host: macos-14
- host: macos-latest
target: 'aarch64-apple-darwin'
- host: windows-latest
target: 'x86_64-pc-windows-msvc'
node: ['18', '20']
node: ['18', '20', '22']
runs-on: ${{ matrix.settings.host }}

steps:
Expand Down Expand Up @@ -300,7 +309,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['18', '20']
node: ['18', '20', '22']
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -351,7 +360,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['18', '20']
node: ['18', '20', '22']
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -404,7 +413,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['20', '21']
node: ['20', '22']
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -523,7 +532,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['18', '20']
node: ['18', '20', '22']
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -579,7 +588,7 @@ jobs:

rust-test:
name: stable - macOS - cargo - test
runs-on: macos-14
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
Expand All @@ -589,13 +598,13 @@ jobs:
- name: Install
uses: ./.github/actions/setup-rust
with:
targets: x86_64-apple-darwin
targets: aarch64-apple-darwin

- name: Install dependencies
run: yarn install --immutable --mode=skip-build

- name: Install nasm
run: brew install nasm llvm
- name: Install llvm
run: brew install llvm

- name: Download skia binary
run: node ./scripts/release-skia-binary.mjs --download
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/skia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ jobs:
run: echo "${PWD}/depot_tools" >> $GITHUB_PATH
shell: bash

- name: Install build tools
run: |
sudo apt-get update
sudo apt-get install ninja-build -y

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
Expand Down Expand Up @@ -353,6 +358,11 @@ jobs:
run: echo "${PWD}/depot_tools" >> $GITHUB_PATH
shell: bash

- name: Install build tools
run: |
sudo apt-get update
sudo apt-get install ninja-build -y

- name: Compile skia
run: node ./scripts/build-skia.js --target=aarch64-linux-android

Expand All @@ -363,3 +373,40 @@ jobs:
run: node ./scripts/release-skia-binary.mjs --upload --target=aarch64-linux-android
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-riscv64-linux-gnu:
if: "!contains(github.event.head_commit.message, 'skip skia')"
name: stable - riscv64-linux-gnu - build skia
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'
- uses: actions/setup-python@v5
with:
python-version: '3.x'
architecture: 'x64'
- name: Set env
run: echo "${PWD}/depot_tools" >> $GITHUB_PATH
shell: bash
- name: Install cross compile tools
run: |
sudo apt-get update
sudo apt-get install ninja-build gcc-riscv64-linux-gnu g++-riscv64-linux-gnu -y
- name: Compile skia
run: node ./scripts/build-skia.js --target=riscv64gc-unknown-linux-gnu
env:
CC: riscv64-linux-gnu-gcc
CXX: riscv64-linux-gnu-g++
- name: Install dependencies
run: yarn install --immutable --mode=skip-build

- name: Upload release
run: node ./scripts/release-skia-binary.mjs --upload --target=riscv64gc-unknown-linux-gnu
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14 changes: 12 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,9 @@ fn main() {
if compile_target_env != "gnu" {
build.cpp_set_stdlib("stdc++");
} else {
build.cpp_set_stdlib("c++").flag("-static");
println!("cargo:rustc-link-lib=static=c++");
match compile_target_arch.as_str() {
"aarch64" => {
link_libcxx(&mut build);
build
.include(
"/usr/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot/usr/include",
Expand All @@ -176,10 +175,16 @@ fn main() {
println!("cargo:rustc-link-search=/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5");
}
"x86_64" => {
link_libcxx(&mut build);
build.include("/usr/lib/llvm-18/include/c++/v1");
println!("cargo:rustc-link-search=/usr/lib/llvm-18/lib");
}
"riscv64" => {
println!("cargo:rustc-link-search=/usr/lib/gcc-cross/riscv64-linux-gnu/11");
println!("cargo:rustc-link-lib=static=atomic");
}
"arm" => {
link_libcxx(&mut build);
let gcc_version = String::from_utf8(
process::Command::new("ls")
.arg("/usr/arm-linux-gnueabihf/include/c++")
Expand Down Expand Up @@ -242,3 +247,8 @@ fn main() {
println!("cargo:rustc-link-lib=static=skshaper");
napi_build::setup();
}

fn link_libcxx(build: &mut cc::Build) {
build.cpp_set_stdlib("c++").flag("-static");
println!("cargo:rustc-link-lib=static=c++");
}
12 changes: 12 additions & 0 deletions js-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,18 @@ switch (platform) {
loadError = e
}
break
case 'riscv64':
localFileExisted = existsSync(join(__dirname, 'skia.linux-riscv64-gnu.node'))
try {
if (localFileExisted) {
nativeBinding = require('./skia.linux-riscv64-gnu.node')
} else {
nativeBinding = require('@napi-rs/canvas-linux-riscv64-gnu')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`)
}
Expand Down
8 changes: 4 additions & 4 deletions npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
"cpu": [
"arm64"
],
"libc": [
"glibc"
],
"main": "skia.linux-arm64-gnu.node",
"files": [
"skia.linux-arm64-gnu.node"
Expand Down Expand Up @@ -39,5 +36,8 @@
"repository": {
"type": "git",
"url": "git+https://github.com/Brooooooklyn/canvas.git"
}
},
"libc": [
"glibc"
]
}
8 changes: 4 additions & 4 deletions npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
"cpu": [
"arm64"
],
"libc": [
"musl"
],
"main": "skia.linux-arm64-musl.node",
"files": [
"skia.linux-arm64-musl.node"
Expand Down Expand Up @@ -39,5 +36,8 @@
"repository": {
"type": "git",
"url": "git+https://github.com/Brooooooklyn/canvas.git"
}
},
"libc": [
"musl"
]
}
3 changes: 3 additions & 0 deletions npm/linux-riscv64-gnu/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `@napi-rs/canvas-linux-riscv64-gnu`

This is the **riscv64-unknown-linux-gnu** binary for `@napi-rs/canvas`
43 changes: 43 additions & 0 deletions npm/linux-riscv64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@napi-rs/canvas-linux-riscv64-gnu",
"version": "0.1.62",
"os": [
"linux"
],
"cpu": [
"riscv64"
],
"main": "skia.linux-riscv64-gnu.node",
"files": [
"skia.linux-riscv64-gnu.node"
],
"description": "Canvas for Node.js with skia backend",
"keywords": [
"napi-rs",
"NAPI",
"N-API",
"Rust",
"node-addon",
"node-addon-api",
"canvas",
"image",
"pdf",
"svg",
"skia"
],
"license": "MIT",
"engines": {
"node": ">= 10"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Brooooooklyn/canvas.git"
},
"libc": [
"glibc"
]
}
8 changes: 4 additions & 4 deletions npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
"cpu": [
"x64"
],
"libc": [
"glibc"
],
"main": "skia.linux-x64-gnu.node",
"files": [
"skia.linux-x64-gnu.node"
Expand Down Expand Up @@ -39,5 +36,8 @@
"repository": {
"type": "git",
"url": "git+https://github.com/Brooooooklyn/canvas.git"
}
},
"libc": [
"glibc"
]
}
8 changes: 4 additions & 4 deletions npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"x64"
],
"main": "skia.linux-x64-musl.node",
"libc": [
"musl"
],
"files": [
"skia.linux-x64-musl.node"
],
Expand Down Expand Up @@ -39,5 +36,8 @@
"repository": {
"type": "git",
"url": "git+https://github.com/Brooooooklyn/canvas.git"
}
},
"libc": [
"musl"
]
}
3 changes: 1 addition & 2 deletions npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
],
"main": "skia.win32-x64-msvc.node",
"files": [
"skia.win32-x64-msvc.node",
"icudtl.dat"
"skia.win32-x64-msvc.node"
],
"description": "Canvas for Node.js with skia backend",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"aarch64-unknown-linux-gnu",
"aarch64-unknown-linux-musl",
"aarch64-apple-darwin",
"aarch64-linux-android"
"aarch64-linux-android",
"riscv64-unknown-linux-gnu"
]
}
},
Expand Down
9 changes: 7 additions & 2 deletions scripts/build-skia.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ if (process.env.SKIP_SYNC_SK_DEPS !== 'false' && process.env.SKIP_SYNC_SK_DEPS !
exec('python ./tools/git-sync-deps')
}

const CC = PLATFORM_NAME === 'win32' ? '\\"clang-cl\\"' : '"clang"'
const CXX = PLATFORM_NAME === 'win32' ? '\\"clang-cpp\\"' : '"clang++"'
let CC = PLATFORM_NAME === 'win32' ? '\\"clang-cl\\"' : '"clang"'
let CXX = PLATFORM_NAME === 'win32' ? '\\"clang-cpp\\"' : '"clang++"'
let ExtraCflagsCC = ''
let ExtraSkiaBuildFlag = ''
let ExtraCflags
Expand Down Expand Up @@ -233,6 +233,11 @@ switch (TARGET_TRIPLE) {
break
case '':
break
case 'riscv64gc-unknown-linux-gnu':
ExtraSkiaBuildFlag += ' target_cpu="riscv64" target_os="linux"'
CC = '"riscv64-linux-gnu-gcc"'
CXX = '"riscv64-linux-gnu-g++"'
break;
default:
throw new TypeError(`[${TARGET_TRIPLE}] is not a valid target`)
}
Expand Down
Loading