diff --git a/.github/workflows/bin.yaml b/.github/workflows/bin.yaml new file mode 100644 index 00000000..9d3c9b4e --- /dev/null +++ b/.github/workflows/bin.yaml @@ -0,0 +1,91 @@ +name: Binaries + +on: + release: + types: [created] + push: + branches: ["mara/npx"] + +env: + PKG_CONFIG_ALLOW_CROSS: 1 + +jobs: + build: + name: Build Binaries + runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - os: ubuntu-latest + target: aarch64-unknown-linux-gnu + - os: ubuntu-latest + target: arm-unknown-linux-gnueabihf + - os: macos-latest + target: x86_64-apple-darwin + - os: macos-latest + target: aarch64-apple-darwin + - os: windows-latest + target: x86_64-pc-windows-msvc + - os: windows-latest + target: i686-pc-windows-msvc + steps: + - uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: ${{ matrix.target }} + override: true + + - name: Cache + uses: Swatinem/rust-cache@v2 + + - name: Setup Linux + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf + echo "PKG_CONFIG_PATH=/usr/arm-linux-gnueabihf/lib/pkgconfig" >> $GITHUB_ENV + + - name: Setup macOS + if: runner.os == 'macOS' + run: | + brew install openssl + echo "PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig" >> $GITHUB_ENV + echo "OPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include" >> $GITHUB_ENV + echo "OPENSSL_LIB_DIR=/usr/local/opt/openssl/lib" >> $GITHUB_ENV + + - name: Setup Windows + if: runner.os == 'Windows' + run: + echo "skipped" + + - name: Build + run: cargo build --release --target ${{ matrix.target }} + + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.target }} + path: target/${{ matrix.target }}/release/* + + publish: + name: Publish Binaries + needs: build + runs-on: ubuntu-latest + steps: + - name: Download Artifacts + uses: actions/download-artifact@v2 + with: + path: artifacts + + - name: Release Binaries + uses: softprops/action-gh-release@v1 + with: + files: artifacts/* + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/book.yml b/.github/workflows/book.yaml similarity index 96% rename from .github/workflows/book.yml rename to .github/workflows/book.yaml index f8e39e2d..bcf65770 100644 --- a/.github/workflows/book.yml +++ b/.github/workflows/book.yaml @@ -3,7 +3,8 @@ name: Book on: push: branches: ["main"] - workflow_dispatch: + paths: + - 'docs/**' permissions: contents: read diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index 49de2349..bfd2b37c 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -3,7 +3,19 @@ name: Buffrs CLI on: push: branches: ["main"] + paths: + - 'Cargo.lock' + - 'Cargo.toml' + - 'deny.toml' + - 'src/**' + - 'registry/**' pull_request: + paths: + - 'Cargo.lock' + - 'Cargo.toml' + - 'deny.toml' + - 'src/**' + - 'registry/**' env: MINIMUM_LINE_COVERAGE_PERCENT: 35 @@ -64,10 +76,3 @@ jobs: - uses: Swatinem/rust-cache@v2 - run: cargo install typos-cli || true - run: typos - nix: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: cachix/install-nix-action@v22 - - uses: DeterminateSystems/magic-nix-cache-action@main - - run: nix flake check diff --git a/.github/workflows/nix.yaml b/.github/workflows/nix.yaml new file mode 100644 index 00000000..79cbb208 --- /dev/null +++ b/.github/workflows/nix.yaml @@ -0,0 +1,21 @@ +name: Nix Flake + +on: + push: + branches: ["main"] + paths: + - 'flake.nix' + - 'flake.lock' + pull_request: + paths: + - 'flake.nix' + +jobs: + nix: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v22 + - uses: DeterminateSystems/magic-nix-cache-action@main + - run: nix flake check + - 'flake.lock' diff --git a/.github/workflows/registry.yml b/.github/workflows/registry.yml index 18232e01..2e8e0630 100644 --- a/.github/workflows/registry.yml +++ b/.github/workflows/registry.yml @@ -3,7 +3,19 @@ name: Buffrs Registry on: push: branches: ["main"] + paths: + - 'Cargo.lock' + - 'Cargo.toml' + - 'deny.toml' + - 'src/**' + - 'registry/**' pull_request: + paths: + - 'Cargo.lock' + - 'Cargo.toml' + - 'deny.toml' + - 'src/**' + - 'registry/**' env: MINIMUM_LINE_COVERAGE_PERCENT: 5 diff --git a/Cargo.lock b/Cargo.lock index c987f172..c3a5754d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1125,6 +1125,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-src" +version = "300.1.6+3.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439fac53e092cd7442a3660c85dde4643ab3b5bd39040912388dcdabf6b88085" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.93" @@ -1133,6 +1142,7 @@ checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" dependencies = [ "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] diff --git a/Cargo.toml b/Cargo.toml index fa3c1853..96196ec0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ bytes = "1.0" clap = { version = "4.3", features = ["cargo", "derive"] } diff-struct = { version = "0.5.3", optional = true } flate2 = "1" -git2 = { version = "0.18.1", optional = true } +git2 = { version = "0.18.1", features = ["vendored-openssl", "vendored-libgit2"], optional = true } hex = "0.4.3" home = "0.5.5" human-panic = "1" diff --git a/pkgs/npm/README.md b/pkgs/npm/README.md new file mode 100644 index 00000000..202ed1db --- /dev/null +++ b/pkgs/npm/README.md @@ -0,0 +1 @@ +# buffrs diff --git a/pkgs/npm/bin/.gitkeep b/pkgs/npm/bin/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/pkgs/npm/download.js b/pkgs/npm/download.js new file mode 100644 index 00000000..86c559c9 --- /dev/null +++ b/pkgs/npm/download.js @@ -0,0 +1,50 @@ +const fs = require('fs'); +const https = require('https'); +const os = require('os'); +const pkg = require('./package.json'); + +const download = (url, dest) => { + return new Promise((resolve, reject) => { + const file = fs.createWriteStream(dest); + https.get(url, (response) => { + if (response.statusCode !== 200) { + reject(new Error(`Failed to download: ${response.statusCode}`)); + return; + } + response.pipe(file); + }); + + file.on('finish', () => { + file.close(resolve); + }); + + file.on('error', (err) => { + fs.unlink(dest, () => reject(err)); + }); + }); +}; + +const install = async () => { + const arch = os.arch(); + const version = pkg.version; + + let platform = os.platform(); + let extension = ""; + + if (["win32", "cygwin"].includes(process.platform)) { + os = "windows"; + extension = ".exe"; + } + + const url = `https://github.com/helsing-ai/buffrs/releases/download/v${version}/buffrs-${platform}-${arch}${extension}`; + const file = `./bin/buffrs-${platform}-${arch}${extension}`; + + try { + await download(url, file); + console.log('Buffrs downloaded successfully'); + } catch (e) { + console.error('Failed to download binary:', e); + } +}; + +install() diff --git a/pkgs/npm/package-lock.json b/pkgs/npm/package-lock.json new file mode 100644 index 00000000..0fb51138 --- /dev/null +++ b/pkgs/npm/package-lock.json @@ -0,0 +1,15 @@ +{ + "name": "buffrs", + "version": "0.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "buffrs", + "version": "0.0.1", + "hasInstallScript": true, + "license": "MIT", + "devDependencies": {} + } + } +} diff --git a/pkgs/npm/package.json b/pkgs/npm/package.json new file mode 100644 index 00000000..f3d2e27c --- /dev/null +++ b/pkgs/npm/package.json @@ -0,0 +1,13 @@ +{ + "name": "buffrs", + "version": "0.0.1", + "description": "buffrs", + "main": "src/main.js", + "scripts": { + "preinstall": "node download.js" + }, + "author": "Mara Schulke ", + "license": "MIT", + "dependencies": {}, + "devDependencies": {} +} diff --git a/pkgs/npm/src/main.js b/pkgs/npm/src/main.js new file mode 100644 index 00000000..77b2f94a --- /dev/null +++ b/pkgs/npm/src/main.js @@ -0,0 +1,43 @@ +#!/usr/bin/env node + +import { spawnSync } from "child_process"; + +/** + * Returns the executable path which is located inside `node_modules` + * The naming convention is app-${os}-${arch} + * If the platform is `win32` or `cygwin`, executable will include a `.exe` extension. + * @see https://nodejs.org/api/os.html#osarch + * @see https://nodejs.org/api/os.html#osplatform + * @example "x/xx/node_modules/app-darwin-arm64" + */ +function getExePath() { + const arch = process.arch; + const os = process.platform as string; + + let extension = ""; + + if (["win32", "cygwin"].includes(process.platform)) { + os = "windows"; + extension = ".exe"; + } + + try { + // Since the binary will be located inside `node_modules`, we can simply call `require.resolve` + return require.resolve(`buffrs/bin/buffrs-${os}-${arch}${extension}`); + } catch (e) { + throw new Error( + `Couldn't find buffrs binary inside node_modules for ${os}-${arch}` + ); + } +} + +/** + * Runs the application with args using nodejs spawn + */ +function run() { + const args = process.argv.slice(2); + const processResult = spawnSync(getExePath(), args, { stdio: "inherit" }); + process.exit(processResult.status ?? 0); +} + +run();