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

Add Pre-build Binaries #12

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7285d25
add pre-build binary
rafaelmaeuer Jun 21, 2022
d4a6c6b
update version, dependencies and readme
rafaelmaeuer Jun 21, 2022
2605959
create changelog from git history
rafaelmaeuer Jun 21, 2022
eb983c0
use lib instead of pre-build binary again
rafaelmaeuer Jun 27, 2022
813d852
add cross-platform build script for binaries
rafaelmaeuer Jun 27, 2022
8f2a08e
add pre-build binaries for most common platforms
rafaelmaeuer Jun 27, 2022
e6be4ed
add arch and platform checks
rafaelmaeuer Jun 27, 2022
b709266
update npm scripts and changelog
rafaelmaeuer Jun 27, 2022
fb90c9e
update readme
rafaelmaeuer Jun 27, 2022
f03dd94
update lib and build-script for linux-musl
rafaelmaeuer Jun 29, 2022
397b97f
update pre-build binaries
rafaelmaeuer Jun 29, 2022
f181670
update version and changelog
rafaelmaeuer Jun 29, 2022
9d0d20f
update readme
rafaelmaeuer Jun 29, 2022
88174c1
Create dependabot.yml
rafaelmaeuer Dec 19, 2022
5cbd77b
Update dependabot.yml
rafaelmaeuer Dec 19, 2022
5fc190e
chore: update format of package.json
rafaelmaeuer Dec 19, 2022
10e50c9
chore: update node-dependencies
rafaelmaeuer Dec 19, 2022
9a0e6aa
chore: npm audit for peer-dependencies
rafaelmaeuer Dec 19, 2022
13ef215
chore: update github/actions
rafaelmaeuer Dec 19, 2022
eca66ef
fix: update compatible node versions
rafaelmaeuer Dec 19, 2022
dad22fd
chore: update pre-build binaries
rafaelmaeuer Dec 19, 2022
77f2e1f
chore: update version and changelog
rafaelmaeuer Dec 19, 2022
675c75e
fix: update version in cargo.toml
rafaelmaeuer Dec 19, 2022
e662b6c
fix: update checks for ci workflow
rafaelmaeuer Dec 19, 2022
b629203
fix: command of ci workflow check
rafaelmaeuer Dec 19, 2022
ee23761
fix: eslint linebreaks for windows
rafaelmaeuer Dec 19, 2022
c5470fb
chore: update changelog
rafaelmaeuer Dec 19, 2022
c4903ca
fix: improve actions run logic
rafaelmaeuer Dec 19, 2022
acb6229
fix: replace rust toolchain action
rafaelmaeuer Dec 19, 2022
8e41533
fix: remove old params from rust-action
rafaelmaeuer Dec 19, 2022
25f12cd
Merge pull request #12 from swrlab/dev/update-2.1.0
rafaelmaeuer Dec 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/dependabot.yml
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
open-pull-requests-limit: 10
schedule:
interval: 'weekly'
day: 'sunday'
- package-ecosystem: 'github-actions'
directory: '/'
open-pull-requests-limit: 10
schedule:
interval: 'weekly'
day: 'sunday'
25 changes: 12 additions & 13 deletions .github/workflows/ci.yml
@@ -1,7 +1,12 @@
name: CI

on: [push, pull_request]

on:
workflow_dispatch:
push:
branches:
- master
- dev/*

jobs:
tests:
strategy:
Expand All @@ -12,22 +17,16 @@ jobs:
- macos-latest
- windows-latest
node-version:
- 12.x
- 14.x
- 15.x
- 16.x
- 18.x
name: Use ${{ matrix.node-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build --if-present
- run: npm test
- run: npm run check
97 changes: 97 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,97 @@
# node-crc / Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.1.0] - 2022-12-19

- feat: activate dependabot checks
- feat: add eslint in ci-automation
- chore: update github/actions
- chore: update node-js versions
- chore: update node-dependencies
- chore: update prebuild-binaries
- fix: eslint linebreaks for windows
- fix: improve actions run logic
- fix: replace rust toolchain action

## [2.0.15] - 2022-06-29

- feat: add binaries for linux-musl
- chore: update cross-build script

## [2.0.14] - 2022-06-27

- feat: add pre-build binaries
- feat: add cross-build script
- chore: update node-dependencies

## [2.0.13] - 2022-05-12

- update project
- remove extern crate
- update scripts

## [2.0.11] - 2021-06-27

- update dependencies

## [2.0.10] - 2021-06-10

- update .eslintrc

## [2.0.9] - 2021-06-07

- update readme

## [2.0.7] - 2021-06-03

- fix tests
- fix .eslintrc
- fix Cargo.toml

## [2.0.3] - 2021-06-02

- update project
- add rust toolchain

## [1.3.2] - 2021-05-30

- add `@types/node`

## [1.3.1] - 2021-05-28

- update project

## [1.3.0] - 2020-02-21

- fix bugs
- add `crc64jones`

## [1.2.2] - 2018-03-29

- update

## [1.2.1] - 2017-10-29

- fixed the createFalse function

## [1.2.0] - 2017-10-03

- update modules
- support node `8.6.0+`

## [1.1.1] - 2017-09-05

- add module definition for typescript

## [1.1.0] - 2017-08-23

- update modules
- remove `napi_create_number`

## [1.0.1] - 2017-06-23

- release version
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "node-crc"
version = "2.0.12"
version = "2.1.0"
edition = "2021"
repository = "https://github.com/magiclen/node-crc"
homepage = "https://magiclen.org/node-js-crc/"
Expand Down
17 changes: 16 additions & 1 deletion README.md
Expand Up @@ -5,7 +5,17 @@ CRC For Node.js

To compute CRC values by providing the length of bits, expression, reflection, an initial value and a final xor value. It has many built-in CRC functions.

You need to set up the Rust development environment: [rustup](https://rustup.rs/)
For versions 2.0.0 - 2.0.13 you need to set up the Rust development environment: [rustup](https://rustup.rs/)

Since version 2.0.15 pre-build [binaries](./bin) for following platforms can be used:

- macOS x64
- macOS ARM64
- Linux x64 (gnu/musl)
- Linux x86 (gnu/musl)
- Linux ARM64 (gnu/musl)
- Windows x64
- Windows x86

## Usage

Expand Down Expand Up @@ -113,9 +123,14 @@ const result = crc.crc32(Buffer.from("hello", "utf8")).toString("hex");
const result2 = crc.crc64(Buffer.from("world", "utf8")).toString("hex");
```

## Pre-Build

To build the binaries, install Docker and Rust-Toolchain. Then execute `npm run build:binary`.

## TODO

1. CRC class to compute large data
2. Build binaries with github actions

## License

Expand Down
Binary file added bin/darwin-arm64.node
Binary file not shown.
Binary file added bin/darwin-x64.node
Binary file not shown.
Binary file added bin/linux-arm64-gnu.node
Binary file not shown.
Binary file added bin/linux-arm64-musl.node
Binary file not shown.
Binary file added bin/linux-ia32-gnu.node
Binary file not shown.
Binary file added bin/linux-ia32-musl.node
Binary file not shown.
Binary file added bin/linux-x64-gnu.node
Binary file not shown.
Binary file added bin/linux-x64-musl.node
Binary file not shown.
Binary file added bin/win32-ia32.node
Binary file not shown.
Binary file added bin/win32-x64.node
Binary file not shown.
79 changes: 79 additions & 0 deletions build.sh
@@ -0,0 +1,79 @@
#!/usr/bin/env bash

# Exit when any command fails
set -e

# Define archs [0], libs [1] and targets [2]

# WINDOWS
declare -a win32=(i686-pc-windows-gnu node_crc.dll win32-ia32.node)
declare -a win64=(x86_64-pc-windows-gnu node_crc.dll win32-x64.node)

# LINUX GNU
declare -a linux32gnu=(i686-unknown-linux-gnu libnode_crc.so linux-ia32-gnu.node)
declare -a linux64gnu=(x86_64-unknown-linux-gnu libnode_crc.so linux-x64-gnu.node)
declare -a linuxArm64gnu=(aarch64-unknown-linux-gnu libnode_crc.so linux-arm64-gnu.node)

# LINUX MUSL
declare -a linux32musl=(i686-unknown-linux-musl libnode_crc.so linux-ia32-musl.node)
declare -a linux64musl=(x86_64-unknown-linux-musl libnode_crc.so linux-x64-musl.node)
declare -a linuxArm64musl=(aarch64-unknown-linux-musl libnode_crc.so linux-arm64-musl.node)

# MACOS
declare -a darwin64=(x86_64-apple-darwin libnode_crc.dylib darwin-x64.node)
declare -a darwinArm64=(aarch64-apple-darwin libnode_crc.dylib darwin-arm64.node)

# Sum archs, libs and targets in arrays
declare -a archs=("${win32[0]}" "${win64[0]}" "${linux32gnu[0]}" "${linux32musl[0]}" "${linux64gnu[0]}" "${linux64musl[0]}" "${linuxArm64gnu[0]}" "${linuxArm64musl[0]}" "${darwin64[0]}" "${darwinArm64[0]}")
declare -a libs=("${win32[1]}" "${win64[1]}" "${linux32gnu[1]}" "${linux32musl[1]}" "${linux64gnu[1]}" "${linux64musl[1]}" "${linuxArm64gnu[1]}" "${linuxArm64musl[1]}" "${darwin64[1]}" "${darwinArm64[1]}")
declare -a targets=("${win32[2]}" "${win64[2]}" "${linux32gnu[2]}" "${linux32musl[2]}" "${linux64gnu[2]}" "${linux64musl[2]}" "${linuxArm64gnu[2]}" "${linuxArm64musl[2]}" "${darwin64[2]}" "${darwinArm64[2]}")

# Set debug or release flavor
flavor=release

# Loop over archs and build each target
for (( i=0; i<${#archs[@]}; i++ )); do
temp=target/"$flavor"
export="target/${archs[i]}/$flavor/${libs[i]}"
destination="bin/${targets[i]}"

# Check if binary file already exists
if [[ -f "$destination" ]]; then
echo
echo "Skipping ${archs[i]} (binary exists)"
echo "==========================================="
else
# Install toolchain and use cargo for darwin
if [[ "${archs[i]}" = *"darwin"* ]]; then
echo
echo "Install toolchain for ${archs[i]}"
echo "========================================"
rustup target add "${archs[i]}"

echo
echo "Building binary for ${archs[i]}"
cargo build --"$flavor" --target="${archs[i]}"
else
echo
echo "Building binary for ${archs[i]}"
echo "========================================"
# Add build flags for linux musl variant
if [[ "${archs[i]}" = *"musl"* ]]; then
RUSTFLAGS="-C target-feature=-crt-static" cross build --"$flavor" --target="${archs[i]}"
else
cross build --"$flavor" --target="${archs[i]}"
fi
fi

echo
echo "Copy binary ${libs[i]} to bin/${targets[i]}"
cp "$export" "$destination"

echo
echo "Clean build folder: targets/$flavor"
echo
rimraf "$temp"

echo "Done"
fi
done
24 changes: 23 additions & 1 deletion lib/lib.js
@@ -1,9 +1,31 @@
"use strict";
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable camelcase */
Object.defineProperty(exports, "__esModule", { value: true });
exports.crc16riello = exports.crc16mcrf4cc = exports.crc16maxim = exports.crc16genibus = exports.crc16en_13757 = exports.crc16dnp = exports.crc16dect_x = exports.crc16dect_r = exports.crc16dds_110 = exports.crc16cdma2000 = exports.crc16buypass = exports.crc16aug_ccitt = exports.crc16ccitt_false = exports.crc16 = exports.crc15mpt1327 = exports.crc15can = exports.crc14gsm = exports.crc14darc = exports.crc13bbc = exports.crc12gsm = exports.crc12cdma2000 = exports.crc12 = exports.crc11 = exports.crc10gsm = exports.crc10cdma2000 = exports.crc10 = exports.crc8wcdma = exports.crc8rohc = exports.crc8maxim = exports.crc8itu = exports.crc8icode = exports.crc8ebu = exports.crc8dvb_s2 = exports.crc8darc = exports.crc8cdma2000 = exports.crc8 = exports.crc7umts = exports.crc7 = exports.crc6itu = exports.crc6gsm = exports.crc6darc = exports.crc6cdma2000_b = exports.crc6cdma2000_a = exports.crc5usb = exports.crc5itu = exports.crc5epc = exports.crc4interlaken = exports.crc4itu = exports.crc3gsm = exports.crc = void 0;
exports.crc64jones = exports.crc64we = exports.crc64iso = exports.crc64 = exports.crc40gsm = exports.crc32xfer = exports.crc32jamcrc = exports.crc32q = exports.crc32posix = exports.crc32mpeg2 = exports.crc32d = exports.crc32c = exports.crc32bzip2 = exports.crc32mhash = exports.crc32 = exports.crc30cdma = exports.crc24os9 = exports.crc24lte_b = exports.crc24lte_a = exports.crc24flexray_b = exports.crc24flexray_a = exports.crc24ble = exports.crc24 = exports.crc21can = exports.crc17can = exports.crc16xmodem = exports.crc16_x25 = exports.crc16modbus = exports.crc16kermit = exports.crc_a = exports.crc16usb = exports.crc16tms13157 = exports.crc16teledisk = exports.crc16t10_dif = void 0;
const _crc = require("../index.node");
const detect_libc_1 = require("detect-libc");
/**
* Check linux family to select correct libc
*/
const getLinuxFamily = () => {
switch ((0, detect_libc_1.familySync)()) {
case detect_libc_1.GLIBC:
return "-gnu";
case detect_libc_1.MUSL:
return "-musl";
default:
return "";
}
};
/**
* Check platform and arch to load correct prebuild binary
*/
const arch = process.arch;
const platform = process.platform;
const family = platform === "linux" ? getLinuxFamily() : "";
const binary = `../bin/${platform}-${arch}${family}.node`;
const _crc = require(binary);
/**
* Create a CRC instance by providing the length of bits, expression, reflection, an initial value and a final xor value.
*/
Expand Down