From 306484cbdaf9bb55b388880e6e6f219272a9ea43 Mon Sep 17 00:00:00 2001 From: Dean Srebnik <49134864+load1n9@users.noreply.github.com> Date: Thu, 6 Oct 2022 13:45:30 -0400 Subject: [PATCH] feat: actions to automatically build binaries (#7) --- .github/workflows/build.yml | 57 +++++++++++++++++++++++++++++++++++++ README.md | 12 ++++---- src/native/ffi.ts | 19 +++++++++---- 3 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..6ada7da --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,57 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +jobs: + build: + name: Build ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + compiler: [clang] + fail-fast: false + steps: + - uses: actions/checkout@v2 + + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v1.12 + with: + cmake-version: '3.24.2' + + - name: Build on Windows + shell: bash + if: startsWith(matrix.os, 'windows') + run: | + set -xeuo pipefail + cd native + mkdir build + cd build + cmake .. -G "Unix Makefiles" + make + cd ../.. + - name: Build on Mac & Linux + shell: bash + if: runner.os != 'Windows' + run: | + set -xeuo pipefail + cd native + mkdir build + cd build + cmake .. + make + cd ../.. + - name: Release + uses: softprops/action-gh-release@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: "release draft" + draft: true + files: | + native/build/libnetsaur.so + native/build/libnetsaur.dylib + native/build/libnetsaur.dll \ No newline at end of file diff --git a/README.md b/README.md index 5257ad4..e50ee16 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,14 @@


- - netsaur stars + + netsaur stars - - netsaur releases + + netsaur releases - - netsaur License + + netsaur License


diff --git a/src/native/ffi.ts b/src/native/ffi.ts index 12e8e97..4a3d800 100644 --- a/src/native/ffi.ts +++ b/src/native/ffi.ts @@ -1,3 +1,5 @@ +import { dlopen, FetchOptions } from "https://deno.land/x/plug@1.0.0-rc.3/mod.ts" + const symbols = { matrix_new: { parameters: ["i32", "i32", "u8"], @@ -165,11 +167,18 @@ const symbols = { }, } as const; -export default Deno.dlopen( - new URL(`../../native/build/${Deno.build.os === "windows" ? "" : "lib"}netsaur.${Deno.build.os === "linux" ? "so" : Deno.build.os === "darwin" ? "dylib" : "dll"}`, import.meta.url), - symbols, -) - .symbols; +const opts: FetchOptions = { + name: "netsaur", + url: "https://github.com/denosaurs/netsaur/releases/download/0.1.4/", + prefixes: { + darwin: "lib", + windows: "lib", + linux: "lib", + } +}; + +const mod = await dlopen(opts, symbols); +export default mod.symbols; export function cstr(str: string) { return new TextEncoder().encode(str + "\0");