Skip to content

Commit

Permalink
feat: add riscv64gc-unknown-linux-gnu
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Nov 19, 2024
1 parent 04a0cfd commit 13e6060
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 16 deletions.
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 riscv64-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
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
3 changes: 3 additions & 0 deletions scripts/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export function libPath(lib, hostPlatform, triple, tag = TAG) {
case 'aarch64-linux-android':
platformName = `lib${lib}-android-aarch64.a`
break
case 'riscv64gc-unknown-linux-gnu':
platformName = `lib${lib}-linux-riscv64-gnu.a`
break
default:
throw new TypeError(`[${triple}] is not a valid target`)
}
Expand Down

0 comments on commit 13e6060

Please sign in to comment.