Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
chdsbd committed Jun 16, 2024
1 parent f0dba18 commit cccc656
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
43 changes: 37 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ jobs:
build-linux:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true' || startsWith(github.ref, 'refs/tags/')

strategy:
fail-fast: false
matrix:
include:
- arch: x86_64
target: x86_64-unknown-linux-musl
container: x86_64-musl
- arch: aarch64
target: aarch64-unknown-linux-musl
container: aarch64-musl

runs-on: ubuntu-latest

Expand All @@ -32,25 +43,30 @@ jobs:

- name: Install Toolchain
uses: oxidecomputer/actions-rs_toolchain@ad3f86084a8a5acf2c09cb691421b31cf8af7a36 # pin@oxide/master
with:
toolchain: stable
target: ${{ matrix.target }}
profile: minimal
override: true

- name: Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # pin@v2

- name: Build
run: RUSTFLAGS='-C target-feature=+crt-static' cargo build --target x86_64-unknown-linux-gnu --all --release && ls target && mv target/x86_64-unknown-linux-gnu/release/squawk target/release/squawk-linux-x86_64
run: RUSTFLAGS='-C target-feature=+crt-static' cargo build --target ${{ matrix.target }} --release && mv target/${{ matrix.target }}/release/squawk target/release/squawk-${{ matrix.target }}

- name: Artifact
uses: actions/upload-artifact@v3
with:
name: release
path: target/release/squawk-linux-x86_64
path: target/release/squawk-${{ matrix.target }}

- name: Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # pin@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
target/release/squawk-linux-x86_64
target/release/squawk-${{ matrix.target }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -61,6 +77,16 @@ jobs:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true' || startsWith(github.ref, 'refs/tags/')

strategy:
fail-fast: false
matrix:
include:
- arch: x86_64
target: x86_64-apple-darwin
- arch: arm64
target: aarch64-apple-darwin

name: macOS ${{ matrix.arch }}
runs-on: macos-latest

steps:
Expand All @@ -69,25 +95,30 @@ jobs:

- name: Install Toolchain
uses: oxidecomputer/actions-rs_toolchain@ad3f86084a8a5acf2c09cb691421b31cf8af7a36 # pin@oxide/master
with:
toolchain: stable
target: ${{ matrix.target }}
profile: minimal
override: true

- name: Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # pin@v2

- name: Build for mac
run: cargo build --all --release && mv target/release/squawk target/release/squawk-darwin-x86_64
run: cargo build --release --target=${{ matrix.target }} && mv target/${{ matrix.target }}/release/squawk target/release/squawk-${{ matrix.target }}

- name: Artifact
uses: actions/upload-artifact@v3
with:
name: release
path: target/release/squawk-darwin-x86_64
path: target/release/squawk-${{ matrix.target }}

- name: Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # pin@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
target/release/squawk-darwin-x86_64
target/release/squawk-${{ matrix.target }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
23 changes: 13 additions & 10 deletions js/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,22 @@ const { binaryPath } = require("./helpers")
// e.g.: https://github.com/sbdchd/squawk/releases/download/v0.1.3/squawk-darwin-x86_64
const RELEASES_BASE_URL = "https://github.com/sbdchd/squawk/releases/download"

const SUPPORTED_PLATFORMS = new Set([
'x86_64-apple-darwin',
'aarch64-apple-darwin',
'x86_64-unknown-linux-musl',
'aarch64-unknown-linux-musl',
])

/**
* @param {string} platform
* @param {string} arch
*/
function getDownloadUrl(platform) {
const releasesUrl = `${RELEASES_BASE_URL}/v${pkgInfo.version}/squawk`
switch (platform) {
case "darwin":
return `${releasesUrl}-darwin-x86_64`
case "linux":
return `${releasesUrl}-linux-x86_64`
default:
return null
function getDownloadUrl(platform, arch) {
if (!SUPPORTED_PLATFORMS.has(`${platform}-${arch}`)) {
return null
}
return `${RELEASES_BASE_URL}/v${pkgInfo.version}/squawk-${platform}-${arch}`
}

function getNpmCache() {
Expand Down Expand Up @@ -107,7 +110,7 @@ function getDecompressor(response) {
function downloadBinary() {
const arch = os.arch()
const platform = os.platform()
const downloadUrl = getDownloadUrl(platform)
const downloadUrl = getDownloadUrl(platform, arch)
if (!downloadUrl) {
return Promise.reject(new Error(`unsupported target ${platform}-${arch}`))
}
Expand Down

0 comments on commit cccc656

Please sign in to comment.