@@ -0,0 +1,110 @@
1+name: Build
2+
3+on:
4+ push:
5+ branches: [master]
6+ pull_request:
7+
8+env:
9+ CARGO_TERM_COLOR: always
10+
11+jobs:
12+ build:
13+ strategy:
14+ fail-fast: false
15+ matrix:
16+ include:
17+ - runner: ubuntu-latest
18+ name: linux-x86_64
19+ - runner: macos-latest
20+ name: macos-arm64
21+ - runner: macos-13
22+ name: macos-x86_64
23+ runs-on: ${{ matrix.runner }}
24+ steps:
25+ - uses: actions/checkout@v4
26+
27+ - uses: actions/checkout@v4
28+ with:
29+ repository: ilyakooo0/knot
30+ path: knot
31+
32+ - uses: dtolnay/rust-toolchain@stable
33+
34+ - name: Install musl toolchain
35+ if: runner.os == 'Linux'
36+ run: |
37+ sudo apt-get update
38+ sudo apt-get install -y musl-tools
39+ rustup target add x86_64-unknown-linux-musl
40+
41+ - uses: actions/cache@v4
42+ with:
43+ path: |
44+ ~/.cargo/registry
45+ ~/.cargo/git
46+ knot/target
47+ key: ${{ matrix.name }}-cargo-${{ hashFiles('knot/Cargo.lock') }}
48+
49+ - name: Build knotc
50+ working-directory: knot
51+ run: cargo build --release -p knot-compiler
52+
53+ - name: Build musl runtime
54+ if: runner.os == 'Linux'
55+ working-directory: knot
56+ run: cargo build --release -p knot-runtime --target x86_64-unknown-linux-musl
57+
58+ - name: Compile server (Linux static)
59+ if: runner.os == 'Linux'
60+ run: |
61+ printf '#!/bin/sh\nexec musl-gcc -static "$@"\n' > /tmp/static-cc
62+ chmod +x /tmp/static-cc
63+ CC=/tmp/static-cc \
64+ KNOT_RUNTIME_LIB=${{ github.workspace }}/knot/target/x86_64-unknown-linux-musl/release/libknot_runtime.a \
65+ ./knot/target/release/knotc build server.knot
66+
67+ - name: Compile server (macOS)
68+ if: runner.os == 'macOS'
69+ run: ./knot/target/release/knotc build server.knot
70+
71+ - name: Verify binary
72+ run: file server
73+
74+ - uses: actions/upload-artifact@v4
75+ with:
76+ name: server-${{ matrix.name }}
77+ path: server
78+
79+ release:
80+ needs: build
81+ if: github.ref == 'refs/heads/master' && github.event_name == 'push'
82+ runs-on: ubuntu-latest
83+ permissions:
84+ contents: write
85+ steps:
86+ - uses: actions/download-artifact@v4
87+
88+ - uses: actions/checkout@v4
89+ with:
90+ path: repo
91+
92+ - name: Generate version
93+ id: version
94+ run: echo "tag=$(git -C repo log -1 --format='%cd' --date='format:%Y.%m.%d.%H%M')" >> "$GITHUB_OUTPUT"
95+
96+ - name: Prepare release assets
97+ run: |
98+ for dir in server-*/; do
99+ name="${dir%/}"
100+ mv "${dir}server" "${name}.tmp"
101+ rm -rf "$dir"
102+ mv "${name}.tmp" "$name"
103+ done
104+ chmod +x server-*
105+
106+ - uses: softprops/action-gh-release@v2
107+ with:
108+ tag_name: ${{ steps.version.outputs.tag }}
109+ name: ${{ steps.version.outputs.tag }}
110+ files: server-*