Skip to content

Commit

Permalink
add support linux-x64-musl, linux-aarch64 for nodejs sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
sunli829 committed Sep 23, 2024
1 parent ba48486 commit 5821cd6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 21 deletions.
48 changes: 37 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: x86_64
args: -i python --release --out dist -m python/Cargo.toml
args: -i python --out dist -m python/Cargo.toml
- name: Install built wheel - x86_64
run: |
pip install longport --no-index --find-links dist --force-reinstall
- name: Build wheels - universal2
if: ${{ matrix.python.universal2 }}
uses: PyO3/maturin-action@v1
with:
args: -i python --release --target universal2-apple-darwin --out dist -m python/Cargo.toml
args: -i python --target universal2-apple-darwin --out dist -m python/Cargo.toml
- name: Install built wheel - universal2
if: ${{ matrix.python.universal2 }}
run: |
Expand Down Expand Up @@ -174,7 +174,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: -i python --release --out dist -m python/Cargo.toml
args: -i python --out dist -m python/Cargo.toml
- name: Install built wheel
run: |
pip install longport --no-index --find-links dist --force-reinstall
Expand Down Expand Up @@ -207,7 +207,7 @@ jobs:
with:
target: ${{ matrix.target }}
manylinux: auto
args: -i python${{ matrix.python-version }} --release --out dist -m python/Cargo.toml
args: -i python${{ matrix.python-version }} --out dist -m python/Cargo.toml
- name: Install built wheel
if: matrix.target == 'x86_64'
run: |
Expand Down Expand Up @@ -238,7 +238,7 @@ jobs:
with:
target: ${{ matrix.target }}
manylinux: 2_28
args: -i python${{ matrix.python-version }} --release --out dist -m python/Cargo.toml
args: -i python${{ matrix.python-version }} --out dist -m python/Cargo.toml
- uses: uraimo/run-on-arch-action@v2.2.0
name: Install built wheel
with:
Expand Down Expand Up @@ -273,19 +273,34 @@ jobs:
fail-fast: true
matrix:
settings:
- host: ubuntu-latest
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
build: |
yarn build:debug
strip -x *.node
artifact-name: linux-x64-musl

- host: ubuntu-latest
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
build: |
rustup target add aarch64-unknown-linux-gnu
yarn build:debug --target aarch64-unknown-linux-gnu
aarch64-unknown-linux-gnu-strip *.node
artifact-name: linux-aarch64

- host: macos-13
architecture: x64
build: |
npm run build:debug
yarn build:debug
strip -x *.node
- host: windows-latest
build: npm run build:debug
build: yarn build:debug
architecture: x64

- host: ubuntu-latest
build: |
npm run build:debug
yarn build:debug
strip *.node
- host: macos-13
Expand All @@ -296,7 +311,7 @@ jobs:
export CXX=$(xcrun -f clang++);
SYSROOT=$(xcrun --sdk macosx --show-sdk-path);
export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT";
yarn build --target aarch64-apple-darwin
yarn build:debug --target aarch64-apple-darwin
strip -x *.node
runs-on: ${{ matrix.settings.host }}
Expand All @@ -307,13 +322,15 @@ jobs:

- name: Setup node
uses: actions/setup-node@v3
if: ${{ !matrix.settings.docker }}
with:
node-version: 16
check-latest: true
architecture: ${{ matrix.settings.architecture }}

- name: Install Rust
uses: actions-rs/toolchain@v1
if: ${{ !matrix.settings.docker }}
with:
toolchain: stable
override: true
Expand All @@ -323,13 +340,22 @@ jobs:
- name: Check with clippy
run: cargo clippy -p longport-nodejs --all-features

- name: Install napi-rs/cli
run: npm install -g @napi-rs/cli
- name: Install dependencies
working-directory: nodejs
run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000

- name: Build
working-directory: nodejs
run: ${{ matrix.settings.build }}

- name: Build in Docker
uses: addnab/docker-run-action@v3
if: ${{ matrix.settings.docker }}
with:
image: ${{ matrix.settings.docker }}
options: "--user 0:0 -v ${{ github.workspace }}:/build -w /build/nodejs"
run: ${{ matrix.settings.build }}

check-java-sdk:
needs:
- check-format
Expand Down
49 changes: 40 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,44 @@ jobs:
fail-fast: true
matrix:
settings:
- host: ubuntu-latest
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
build: |
yarn build
strip -x *.node
artifact-name: linux-x64-musl

- host: ubuntu-latest
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
build: |
rustup target add aarch64-unknown-linux-gnu
yarn build --target aarch64-unknown-linux-gnu
aarch64-unknown-linux-gnu-strip *.node
artifact-name: linux-aarch64

# - host: ubuntu-latest
# docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
# build: |
# rustup target add aarch64-unknown-linux-musl
# yarn build --target aarch64-unknown-linux-musl
# /aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node
# artifact-name: linux-aarch64-musl

- host: macos-13
architecture: x64
build: |
npm run build
yarn build
strip -x *.node
artifact-name: macos

- host: windows-latest
build: npm run build
build: yarn build
architecture: x64
artifact-name: windows

- host: ubuntu-latest
build: |
npm run build
yarn build
strip *.node
artifact-name: linux-x64

Expand All @@ -218,29 +241,38 @@ jobs:

- name: Setup node
uses: actions/setup-node@v3
if: ${{ !matrix.settings.docker }}
with:
node-version: 16
check-latest: true
architecture: ${{ matrix.settings.architecture }}

- name: Install Rust
uses: actions-rs/toolchain@v1
if: ${{ !matrix.settings.docker }}
with:
toolchain: stable
override: true
components: rustfmt, clippy
target: ${{ matrix.settings.target }}

- name: Check with clippy
run: cargo clippy -p longport-nodejs --all-features

- name: Install napi-rs/cli
run: npm install -g @napi-rs/cli
- name: Install dependencies
working-directory: nodejs
run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000

- name: Build
if: ${{ !matrix.settings.docker }}
working-directory: nodejs
run: ${{ matrix.settings.build }}

- name: Build in Docker
uses: addnab/docker-run-action@v3
if: ${{ matrix.settings.docker }}
with:
image: ${{ matrix.settings.docker }}
options: "--user 0:0 -v ${{ github.workspace }}:/build -w /build/nodejs"
run: ${{ matrix.settings.build }}

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -802,7 +834,6 @@ jobs:
check-latest: true
- name: Install napi-rs/cli
run: npm install -g @napi-rs/cli

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
Expand Down
12 changes: 11 additions & 1 deletion rust/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::collections::HashMap;
use std::{
collections::HashMap,
fmt::{self, Display},
};

use http::Method;
pub(crate) use http::{header, HeaderValue, Request};
Expand Down Expand Up @@ -38,6 +41,12 @@ impl Language {
}
}

impl Display for Language {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}

/// Push mode for candlestick
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum PushCandlestickMode {
Expand Down Expand Up @@ -216,6 +225,7 @@ impl Config {
/// Create metadata for auth/reconnect request
pub fn create_metadata(&self) -> HashMap<String, String> {
let mut metadata = HashMap::new();
metadata.insert("accept-language".to_string(), self.language.to_string());
if self.enable_overnight {
metadata.insert("need_over_night_quote".to_string(), "true".to_string());
}
Expand Down

0 comments on commit 5821cd6

Please sign in to comment.