Skip to content

Commit

Permalink
chore: compile on windows (#2184)
Browse files Browse the repository at this point in the history
* chore: compile on windows

Nothing works yet, but at least cargo build runs

* Commit from GitHub Actions (test)

---------

Co-authored-by: mise[bot] <[email protected]>
  • Loading branch information
jdx and mise-en-dev authored May 25, 2024
1 parent 70f4b95 commit b563597
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 68 deletions.
110 changes: 92 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: release
on:
push:
tags: ["v*"]
branches: ["release"]
branches: ["release", "win"]
workflow_dispatch:

concurrency:
Expand All @@ -13,19 +13,20 @@ env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
DRY_RUN: ${{ startsWith(github.event.ref, 'refs/tags/v') && '0' || '1' }}
RUSTC_WRAPPER: sccache
SCCACHE_ENDPOINT: minio.jdx.dev
SCCACHE_BUCKET: sccache
SCCACHE_REGION: auto
SCCACHE_S3_NO_CREDENTIALS: ${{ secrets.MINIO_AWS_ACCESS_KEY_ID && '0' || '1' }}
AWS_ACCESS_KEY_ID: ${{ secrets.MINIO_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.MINIO_AWS_SECRET_ACCESS_KEY }}

jobs:
build-tarball:
name: build-tarball-${{matrix.name}}
runs-on: ${{matrix.runs-on}}
timeout-minutes: 45
env:
#RUSTC_WRAPPER: sccache
SCCACHE_ENDPOINT: minio.jdx.dev
SCCACHE_BUCKET: sccache
SCCACHE_REGION: auto
SCCACHE_S3_NO_CREDENTIALS: ${{ secrets.MINIO_AWS_ACCESS_KEY_ID && '0' || '1' }}
AWS_ACCESS_KEY_ID: ${{ secrets.MINIO_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.MINIO_AWS_SECRET_ACCESS_KEY }}
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -70,6 +71,10 @@ jobs:
name: macos-arm64
target: aarch64-apple-darwin
runs-on: macos-14
# - os: windows
# name: win-x64
# target: x86_64-pc-windows-gnu
# runs-on: ubuntu-latest
steps:
- if: matrix.os == 'macos'
uses: apple-actions/import-codesign-certs@v3
Expand All @@ -78,25 +83,74 @@ jobs:
p12-password: ${{ secrets.APPLE_DEVELOPER_ID_APPLICATION_CERTS_P12_PASS }}
- uses: actions/checkout@v4
- uses: mozilla-actions/[email protected]
- uses: actions/cache@v4
- name: cache crates
id: cache-crates
uses: actions/cache@v4
with:
path: ~/.cargo/bin/zipsign
key: ${{ runner.os }}-cargo-zipsign
- run: rustup target add ${{matrix.target}}
- run: rustup toolchain install stable --profile minimal
- if: matrix.os == 'ubuntu'
path: ~/.cargo/registry/cache
key: cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: cargo-registry
- if: matrix.runs-on != 'ubuntu-latest'
run: rustup target add ${{matrix.target}}
- if: matrix.runs-on == 'ubuntu-latest'
uses: taiki-e/install-action@cross
- run: scripts/setup-zipsign.sh
env:
ZIPSIGN: ${{ secrets.ZIPSIGN }}
- run: scripts/build-tarball.sh mise --features openssl/vendored --target ${{matrix.target}}
- run: scripts/build-tarball.sh ${{matrix.target}}
- uses: actions/upload-artifact@v4
with:
name: tarball-${{matrix.target}}
path: |
dist/mise-*.tar.xz
dist/mise-*.tar.gz
if-no-files-found: error
- uses: taiki-e/install-action@v2
with: { tool: cargo-cache }
- if: steps.cache-crates.outputs.cache-hit != 'true'
run: cargo cache --autoclean
- run: ${SCCACHE_PATH} --show-stats
build-tarball-win:
name: build-tarball-win-${{matrix.arch}}
runs-on: windows-latest
timeout-minutes: 45
env:
RUSTC_WRAPPER: sccache
SCCACHE_ENDPOINT: minio.jdx.dev
SCCACHE_BUCKET: sccache
SCCACHE_REGION: auto
SCCACHE_S3_NO_CREDENTIALS: ${{ secrets.MINIO_AWS_ACCESS_KEY_ID && '0' || '1' }}
AWS_ACCESS_KEY_ID: ${{ secrets.MINIO_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.MINIO_AWS_SECRET_ACCESS_KEY }}
strategy:
fail-fast: false
matrix:
include:
- arch: arm64
target: aarch64-pc-windows-msvc
- arch: x64
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v4
- run: rustup target add ${{matrix.target}}
- uses: mozilla-actions/[email protected]
- name: cache crates
id: cache-crates
uses: actions/cache@v4
with:
path: ~/.cargo/registry/cache
key: cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: cargo-registry
- run: scripts/build-tarball.ps1 ${{matrix.target}}
env:
OS: win
ARCH: ${{matrix.arch}}
- uses: actions/upload-artifact@v4
with:
name: tarball-${{matrix.target}}
path: dist/*.zip
if-no-files-found: error
- uses: taiki-e/install-action@v2
with: { tool: cargo-cache }
- if: steps.cache-crates.outputs.cache-hit != 'true'
run: cargo cache --autoclean
e2e-linux:
name: e2e-linux-${{matrix.tranche}}
needs: [build-tarball]
Expand Down Expand Up @@ -196,6 +250,7 @@ jobs:
- rpm
- deb
- e2e-linux
- build-tarball-win
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -205,6 +260,15 @@ jobs:
repository: jdx/mise-docs
path: mise-docs
token: ${{ secrets.RTX_GITHUB_BOT_TOKEN }}
- name: cache zipsign
id: cache-zipsign
uses: actions/cache@v4
with:
path: ~/.cargo/bin/zipsign
key: cargo-zipsign
- run: ./mise/scripts/setup-zipsign.sh
env:
ZIPSIGN: ${{ secrets.ZIPSIGN }}
- name: Install fd-find
run: |
sudo apt-get update
Expand All @@ -228,6 +292,16 @@ jobs:
workdir: mise-docs
- uses: actions/download-artifact@v4
with: { path: artifacts }
- run: ls -R artifacts
- uses: actions/download-artifact@v4
with:
path: artifacts
pattern: |
mise-v*.tar.gz
mise-v*.tar.xz
mise-v*.zip
merge-multiple: true
- run: ls -R artifacts
- run: mise/scripts/release.sh
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ jobs:
- run: |
cargo build --all-features
echo "$PWD/target/debug" >> "$GITHUB_PATH"
- run: ${SCCACHE_PATH} --show-stats
- run: mise install
- run: mise x -- cargo nextest run --all-features
- run: cargo deny check
Expand Down Expand Up @@ -76,6 +75,7 @@ jobs:
author_email: [email protected]
- uses: actions-rust-lang/rustfmt@v1
- run: mise run lint
- run: ${SCCACHE_PATH} --show-stats

nightly:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -111,6 +111,7 @@ jobs:
push: true
author_name: mise[bot]
author_email: [email protected]
- run: ${SCCACHE_PATH} --show-stats

coverage:
name: coverage-${{matrix.tranche}}
Expand Down Expand Up @@ -168,6 +169,7 @@ jobs:
name: coverage-${{matrix.tranche}}.lcov
path: coverage-${{matrix.tranche}}.lcov
if-no-files-found: error
- run: ${SCCACHE_PATH} --show-stats
coverage-report:
name: coverage-report
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ nnnn = 'https://github.com/mise-plugins/rtx-nodejs#main'
abc = '1'

[tasks]
format = "cargo fmt -- --emit=files"
clean = "cargo clean"
release = "cargo release"
signal-test = "node ./test/fixtures/signal-test.js"
Expand Down
2 changes: 1 addition & 1 deletion .mise/tasks/lint-fix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# mise alias=["lint:fix"]
# mise alias=["format", "lint:fix"]
set -euxo pipefail

# Used for shellcheck which needs explicit args
Expand Down
26 changes: 26 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
target.x86_64-unknown-linux-gnu.pre-build = "./scripts/sccache.sh"
target.x86_64-unknown-linux-musl.pre-build = "./scripts/sccache.sh"
#target.aarch64-unknown-linux-gnu.pre-build = "./scripts/sccache.sh"
#target.aarch64-unknown-linux-musl.pre-build = "./scripts/sccache.sh"
#target.armv7-unknown-linux-gnueabihf.pre-build = "./scripts/sccache.sh"
#target.armv7-unknown-linux-musleabihf.pre-build = "./scripts/sccache.sh"
#target.arm-unknown-linux-gnueabi.pre-build = "./scripts/sccache.sh"
#target.arm-unknown-linux-musleabi.pre-build = "./scripts/sccache.sh"
#target.x86_64-apple-darwin.pre-build = "./scripts/sccache.sh"
#target.aarch64-apple-darwin.pre-build = "./scripts/sccache.sh"
#target.aarch64-pc-windows-msvc.pre-build = "./scripts/sccache.sh"
#target.x86_64-pc-windows-msvc.pre-build = "./scripts/sccache.sh"

[build.env]
passthrough = [
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
"RUSTC_WRAPPER",
"SCCACHE_BUCKET",
"SCCACHE_DIR",
"SCCACHE_ENDPOINT",
"SCCACHE_ERROR_LOG",
"SCCACHE_LOG",
"SCCACHE_REGION",
"SCCACHE_S3_NO_CREDENTIALS",
]
13 changes: 13 additions & 0 deletions scripts/build-tarball.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Set-StrictMode -Version Latest
#Set-PSDebug -Trace 1

$Target = $args[0]
$Version = ./scripts/get-version.ps1
$BaseName = "mise-v$Version-$Env:OS-$Env:ARCH"

cargo build --release --features openssl/vendored --target "$Target"
mkdir -p dist/mise/bin
cp "target/$Target/release/mise.exe" dist/mise/bin/mise.exe
cp README.md dist/mise/README.md
cp LICENSE dist/mise/LICENSE
Compress-Archive -Path dist/mise -DestinationPath "dist/$BaseName.zip"
68 changes: 33 additions & 35 deletions scripts/build-tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,16 @@ error() {
exit 1
}

NAME="$1"
shift

for arg in "$@"; do
if [ "${next_target:-}" = 1 ]; then
next_target=
TARGET="$arg"
continue
fi
case "$arg" in
--target)
next_target=1
;;
*) ;;

esac
done

RUST_TRIPLE=${TARGET:-$(rustc -vV | grep ^host: | cut -d ' ' -f2)}
RUST_TRIPLE=${1:-$(rustc -vV | grep ^host: | cut -d ' ' -f2)}
#region os/arch
get_os() {
case "$RUST_TRIPLE" in
*-apple-darwin*)
echo "macos"
;;
*-windows-*)
echo "win"
;;
*-linux-*)
echo "linux"
;;
Expand Down Expand Up @@ -75,36 +60,49 @@ get_suffix() {
#endregion

set -x
VERSION=$(./scripts/get-version.sh)
BASENAME=$NAME-$VERSION-$(get_os)-$(get_arch)$(get_suffix)
os=$(get_os)
arch=$(get_arch)
suffix=$(get_suffix)
version=$(./scripts/get-version.sh)
basename=mise-$version-$os-$arch$suffix

case "$os-$arch" in
linux-arm*)
# don't use sccache
unset RUSTC_WRAPPER
;;
esac

if command -v cross >/dev/null; then
cross build --profile=serious "$@"
cross build --profile=serious --target "$RUST_TRIPLE" --features openssl/vendored
elif command -v zig >/dev/null; then
cargo zigbuild --profile=serious "$@"
cargo zigbuild --profile=serious --target "$RUST_TRIPLE" --features openssl/vendored
else
cargo build --profile=serious "$@"
cargo build --profile=serious --target "$RUST_TRIPLE" --features openssl/vendored
fi
mkdir -p dist/mise/bin
mkdir -p dist/mise/man/man1
mkdir -p dist/mise/share/fish/vendor_conf.d
cp "target/$RUST_TRIPLE/serious/mise" dist/mise/bin/mise
cp "target/$RUST_TRIPLE/serious/mise"* dist/mise/bin
cp README.md dist/mise/README.md
cp LICENSE dist/mise/LICENSE
cp {,dist/mise/}man/man1/mise.1
cp {,dist/mise/}share/fish/vendor_conf.d/mise-activate.fish

if [[ "$(get_os)" == "macos" ]]; then
codesign -f -s "Developer ID Application: Jeffrey Dickey (4993Y37DX6)" dist/mise/bin/mise
if [[ "$os" != "win" ]]; then
cp {,dist/mise/}man/man1/mise.1
cp {,dist/mise/}share/fish/vendor_conf.d/mise-activate.fish
fi

cd dist
tar -cJf "$BASENAME.tar.xz" mise
tar -czf "$BASENAME.tar.gz" mise

if [ -f ~/.zipsign/mise.priv ]; then
zipsign sign tar "$BASENAME.tar.gz" ~/.zipsign/mise.priv
zipsign verify tar "$BASENAME.tar.gz" ../zipsign.pub
if [[ "$os" == "macos" ]]; then
codesign -f -s "Developer ID Application: Jeffrey Dickey (4993Y37DX6)" mise/bin/mise
fi

ls -oh "$BASENAME.tar.xz"
if [[ "$os" == "win" ]]; then
zip -r "$basename.zip" mise
ls -oh "$basename.zip"
else
tar -cJf "$basename.tar.xz" mise
tar -czf "$basename.tar.gz" mise
ls -oh "$basename.tar.xz"
fi
2 changes: 2 additions & 0 deletions scripts/get-version.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$Version = (Get-Content -Path Cargo.toml | Select-String -Pattern '^version = "(.*)"' | ForEach-Object { $_.Matches.Groups[1].Value })
Write-Output $Version
Loading

0 comments on commit b563597

Please sign in to comment.