Skip to content
This repository was archived by the owner on Sep 17, 2023. It is now read-only.

feat: add support for M1 macOS #116

Merged
merged 10 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .cargo/config

This file was deleted.

75 changes: 66 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
---

name: CI

on: [ pull_request ]

# This pipeline validates proposed changes.
#
# CI pipeline based on:
# - https://github.com/heim-rs/heim/blob/master/.github/workflows/ci.yml
# - https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/ci.yml
# - https://github.com/ClementTsang/bottom/blob/master/.github/workflows/ci.yml

env:
BINARY_NAME: monorepo
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1

jobs:
build:
build-docker-image:
runs-on: ubuntu-latest
env:
BINARY_NAME: monorepo
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -32,10 +41,58 @@ jobs:
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Run cargo check
- name: Build docker image
run: docker build -f Dockerfile .

# Room for improvement regarding caching/work-skipping. One example here
# https://github.com/ClementTsang/bottom/blob/92ec3599363c710815c286e975bbb6cc748708dd/.github/workflows/ci.yml#L195
cargo-check:
runs-on: ${{ matrix.triple.os }}
strategy:
matrix:
triple:
- {
os: "ubuntu-latest",
target: "x86_64-unknown-linux-musl",
cross: false,
}
- {
os: "ubuntu-latest",
target: "i686-unknown-linux-musl",
cross: true,
}
- {
os: "macOS-latest",
target: "x86_64-apple-darwin",
cross: false,
}
# aarch64
- {
os: "ubuntu-latest",
target: "aarch64-unknown-linux-musl",
cross: true,
}
# macOS ARM
- {
os: "macOS-latest",
target: "aarch64-apple-darwin",
cross: true,
}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: ${{ matrix.triple.target }}

- name: Cargo check
uses: actions-rs/cargo@v1
with:
command: check

- name: Build docker image
run: docker build -f Dockerfile .
args: --all-targets --verbose --target=${{ matrix.triple.target }}
use-cross: ${{ matrix.triple.cross }}
185 changes: 133 additions & 52 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---

name: Release

on:
Expand All @@ -18,70 +19,90 @@ on:
# - npm publish
# - create GitHub release

env:
BINARY_NAME: monorepo
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1

jobs:
release:

semantic-version:
runs-on: ubuntu-latest
env:
BINARY_NAME: monorepo
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
steps:
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
outputs:
next-version: ${{ steps.calculate.outputs.next-version }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install macOS cross-compilation dependencies
run: |
sudo apt update
sudo apt install --yes \
g++ \
gcc \
libgmp-dev \
libmpc-dev \
libmpfr-dev \
libssl-dev \
libxml2-dev \
zlib1g-dev

- name: Cache osxcross
uses: actions/cache@v3
id: cache-osxcross
with:
path: |
~/osxcross
key: ${{ runner.os }}-osxcross-${{ hashFiles('$GITHUB_WORKSPACE/ci/resource-macos-sdk') }}
# Fetch all history and tags for calculating next semantic version
fetch-depth: 0

- name: Install osxcross
if: steps.cache-osxcross.outputs.cache-hit != 'true'
run: |
sdk=$(cat $GITHUB_WORKSPACE/ci/resource-macos-sdk)
git clone https://github.com/tpoechtrager/osxcross ~/osxcross
pushd ~/osxcross
curl -O $sdk
mv $(basename $sdk) tarballs/
UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh
popd

- name: Add macOS cross-compilation binaries to path
run: echo "$HOME/osxcross/target/bin" >> $GITHUB_PATH

- name: Install GNU/Linux toolchain
uses: actions-rs/toolchain@v1
- name: Configure Node.js
uses: actions/setup-node@v2
with:
profile: minimal
toolchain: stable
target: x86_64-unknown-linux-gnu
node-version: lts/*
cache: npm

- name: Install npm dependencies
run: npm ci --ignore-scripts

- name: Calculate next semantic-release version
id: calculate
run: echo "::set-output name=next-version::$(npx standard-version --dry-run | grep "tagging release" | awk '{ print $NF }')"

# Room for improvement regarding caching/work-skipping. One example here
# https://github.com/ClementTsang/bottom/blob/92ec3599363c710815c286e975bbb6cc748708dd/.github/workflows/ci.yml#L195

### Compile release artifacts
build-release:
runs-on: ${{ matrix.triple.os }}
container: ${{ matrix.triple.container }}
needs:
- semantic-version

strategy:
matrix:
triple:
- {
os: "ubuntu-latest",
target: "x86_64-unknown-linux-musl",
cross: false,
}
- {
os: "ubuntu-latest",
target: "i686-unknown-linux-musl",
cross: true,
}
- {
os: "macOS-latest",
target: "x86_64-apple-darwin",
cross: false,
}
# aarch64
- {
os: "ubuntu-latest",
target: "aarch64-unknown-linux-musl",
cross: true,
}
# macOS ARM
- {
os: "macOS-latest",
target: "aarch64-apple-darwin",
cross: true,
}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install macOS toolchain
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: x86_64-apple-darwin
override: true
target: ${{ matrix.triple.target }}

- name: Cache cargo
uses: actions/cache@v3
Expand All @@ -102,6 +123,66 @@ jobs:
command: install
args: semantic-release-rust --version 1.0.0-alpha.8

- name: Prepare semantic-release for Rust
run: semantic-release-rust prepare ${{ needs.semantic-version.outputs.next-version }}

- name: Cargo build
uses: actions-rs/cargo@v1
with:
command: build
args: --all-targets --verbose --target=${{ matrix.triple.target }} --release
use-cross: ${{ matrix.triple.cross }}

- name: Create release archive
run: |
mkdir dist
mkdir -p builds/typescript-tools-${{ matrix.triple.target }}
cp target/${{ matrix.triple.target }}/release/monorepo builds/typescript-tools-${{ matrix.triple.target }}/
tar -C builds -czvf dist/typescript-tools-${{ matrix.triple.target }}.tar.gz typescript-tools-${{ matrix.triple.target }}

- name: Create checksum
run: shasum --algorithm 256 typescript-tools-${{ matrix.triple.target }}.tar.gz > typescript-tools-${{ matrix.triple.target }}-SHASUMS256.txt
working-directory: ./dist

- name: Upload release artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.triple.target }}
path: |
dist/typescript-tools-${{ matrix.triple.target }}.tar.gz
dist/typescript-tools-${{ matrix.triple.target }}-SHASUMS256.txt
if-no-files-found: error
retention-days: 1

### Perform the semantic-release
release:
runs-on: ubuntu-latest
needs:
- build-release

steps:
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Checkout
uses: actions/checkout@v3

- name: Download release artifacts
uses: actions/download-artifact@v3
with:
path: dist

- name: Display downloaded release artifacts
run: ls -R
working-directory: dist

- name: Combine checksums
run: cat **/typescript-tools-*-SHASUMS256.txt | tee SHASUMS256.txt
working-directory: dist

- name: Invoke semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
28 changes: 19 additions & 9 deletions .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
}
],
"@semantic-release/release-notes-generator",
[
"@semantic-release/exec",
{
"prepareCmd": "./ci/prepare-cmd ${nextRelease.version}"
}
],
[
"@codedependant/semantic-release-docker",
{
Expand All @@ -42,12 +36,28 @@
{
"assets": [
{
"path": "dist/typescript-tools-x86_64-unknown-linux-gnu.tar.gz",
"label": "x86_64-unknown-linux-gnu"
"path": "dist/x86_64-unknown-linux-musl/typescript-tools-x86_64-unknown-linux-musl.tar.gz",
"label": "x86_64-unknown-linux-musl"
},
{
"path": "dist/i686-unknown-linux-musl/typescript-tools-i686-unknown-linux-musl.tar.gz",
"label": "i686-unknown-linux-musl"
},
{
"path": "dist/typescript-tools-x86_64-apple-darwin.tar.gz",
"path": "dist/x86_64-apple-darwin/typescript-tools-x86_64-apple-darwin.tar.gz",
"label": "x86_64-apple-darwin"
},
{
"path": "dist/aarch64-unknown-linux-musl/typescript-tools-aarch64-unknown-linux-musl.tar.gz",
"label": "aarch64-unknown-linux-musl"
},
{
"path": "dist/aarch64-apple-darwin/typescript-tools-aarch64-apple-darwin.tar.gz",
"label": "aarch64-apple-darwin"
},
{
"path": "dist/SHASUMS256.txt",
"label": "SHASUMS256.txt"
}
]
}
Expand Down
5 changes: 5 additions & 0 deletions .versionrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"packageFiles": [],
"bumpFiles": [],
"tagPrefix": ""
}
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ workflow.

## Supported Systems

The following operating systems are supported
The following target triples are supported:

- [x] GNU/Linux
- [x] Mac OS
- [ ] Windows
- x86_64-unknown-linux-musl
- i686-unknown-linux-musl
- x86_64-apple-darwin
- aarch64-unknown-linux-musl
- aarch64-apple-darwin

The following package managers are supported

- [x] npm
- [ ] yarn
- [ ] pnpm
12 changes: 3 additions & 9 deletions bin/monorepo
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
#!/bin/sh

cat <<EOF
This is not the "monorepo" binary, which is usually downloaded via the npm "postinstall"
hook. Was the "npm install" run with the "--ignore-scripts" flag?

Please try reinstalling "@typescript-tools/rust-implementation" or opening a ticket with
details about your use case.
EOF
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this diff

# This is a dummy binary that is the subject of the `npm install` workflow --
# it gets linked into node_modules/.bin and marked as executable before the
# npm postInstall hook executes
Loading