diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3dd1672..5be217c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,6 +15,13 @@ env: TARGET: x86_64-unknown-linux-musl # The systemd user unit that owns the process. See izlek.service. SERVICE: izlek + # `release` keeps fat LTO in one codegen unit for when the last few percent + # are worth five minutes. `dist` is that profile with thin LTO and the cores + # actually used: measured on a 12-core machine, the relink every deploy pays + # for goes from 2m27s to 25s, for a binary this server will never be + # CPU-bound on. See the profile in Cargo.toml. + PROFILE: dist + TOPCOAT: 0.6.2 jobs: deploy: @@ -37,10 +44,20 @@ jobs: with: cache-all-crates: true + # Compiling the CLI from source costs minutes and it changes only when + # the pinned version does, so it is cached on that version alone. + - name: Cache the topcoat CLI + id: topcoat-cache + uses: actions/cache@v4 + with: + path: ~/.cargo/bin/topcoat + key: topcoat-cli-${{ env.TOPCOAT }}-${{ runner.os }} + - name: Install the topcoat CLI # Installed before the cargo config below exists, so the CLI itself is # built for the host and not for musl. - run: cargo install topcoat-cli@0.6.2 --locked + if: steps.topcoat-cache.outputs.cache-hit != 'true' + run: cargo install topcoat-cli@${{ env.TOPCOAT }} --locked - name: Point cargo at musl run: | @@ -60,12 +77,12 @@ jobs: - name: Build the binary and bundle its assets run: | set -euo pipefail - # One compile: this builds izlek-web with the release profile and - # writes out the asset bundle embedded in the binary it produced. - topcoat asset bundle --package izlek-web --release --out dist/assets - cp "target/$TARGET/release/izlek-web" dist/izlek-web - strip dist/izlek-web - ls -l dist dist/assets + # One compile: this builds izlek-web and writes out the asset bundle + # embedded in the binary it produced. + topcoat asset bundle --package izlek-web --profile "$PROFILE" --out stage/assets + cp "target/$TARGET/$PROFILE/izlek-web" stage/izlek-web + strip stage/izlek-web + ls -l stage stage/assets - name: Install SSH keys run: | @@ -94,7 +111,7 @@ jobs: rm -rf -- '${deploy_path}/current.new' mkdir -p -- '${deploy_path}/current.new' " - tar -C dist -czf - . | ssh "$ssh_target" "tar -xzf - -C '${deploy_path}/current.new'" + tar -C stage -czf - . | ssh "$ssh_target" "tar -xzf - -C '${deploy_path}/current.new'" - name: Swap and restart run: | diff --git a/Cargo.toml b/Cargo.toml index ab6bdc5..df2414e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,3 +28,13 @@ toml = "1" [profile.release] codegen-units = 1 lto = true + +# What the deploy builds. Fat LTO and one codegen unit buy the last few +# percent by optimizing the whole program in a single non-parallel pass — +# worth it for something CPU-bound, not for a server whose time goes to +# SQLite, TLS and the network. Thin LTO still optimizes across crates, in +# parallel, so `release` stays available for when the trade is worth making. +[profile.dist] +inherits = "release" +lto = "thin" +codegen-units = 16