Skip to content

Commit

Permalink
build with cross-language lto in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Dec 17, 2024
1 parent f8245ac commit 21d2c41
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 18 deletions.
1 change: 0 additions & 1 deletion .env

This file was deleted.

23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v6
with:
cache-from: type=gha
cache-to: type=gha
outputs: type=local,dest=dist
- uses: actions/upload-artifact@v4
with:
name: lila-openingexplorer
path: dist/usr/local/bin/lila-openingexplorer
- uses: actions/upload-artifact@v4
with:
name: import-lichess
path: dist/usr/local/bin/import-lichess
14 changes: 0 additions & 14 deletions .github/workflows/test.yml

This file was deleted.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ members = [
resolver = "2"

[profile.release]
lto = true
lto = "fat"
strip = "debuginfo"
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Optimized for bookd.lichess.ovh:
# - Ubuntu 22.04 (jammy)
# - AMD Ryzen 5 PRO 3600 (znver2)

FROM docker.io/ubuntu:jammy AS builder

RUN apt-get update && apt-get upgrade --yes && apt-get install --yes git libssl-dev liburing-dev pkg-config wget software-properties-common gpg lsb-release make

# Rust
ADD --chmod=755 https://sh.rustup.rs/ rustup.sh
ENV CARGO_HOME=/usr/local/cargo
ENV PATH=/usr/local/cargo/bin:$PATH
RUN ./rustup.sh -y --no-modify-path --profile minimal --default-toolchain 1.83.0 && rustc --version
ENV RUSTFLAGS="-Ctarget-cpu=znver2 -Clinker-plugin-lto -Clinker=clang-19 -Clink-arg=-fuse-ld=lld-19"
ENV JEMALLOC_SYS_WITH_MALLOC_CONF="abort_conf:true,background_thread:true,metadata_thp:auto,dirty_decay_ms:30000,muzzy_decay_ms:30000"

# Matching clang and lld
ADD --chmod=755 https://apt.llvm.org/llvm.sh llvm.sh
RUN ./llvm.sh 19 && apt-get update && apt-get install --yes clang-19 lld-19
ENV CC=/usr/bin/clang-19
ENV CXX=/usr/bin/clang++-19
ENV LD=/usr/bin/lld-19

# Prepare working directory
WORKDIR /lila-openingexplorer
COPY Cargo.toml Cargo.lock ./
COPY lila-openingexplorer ./lila-openingexplorer
COPY lila-openingexplorer-import ./lila-openingexplorer-import

# Run tests
RUN cargo --config net.git-fetch-with-cli=true fetch
RUN cargo test
RUN cargo bench --features lto

# Build optimized binaries
RUN cargo build --release --features lto

# Final image
FROM docker.io/ubuntu:jammy
RUN apt-get update && apt-get upgrade --yes
COPY --from=builder /lila-openingexplorer/target/release/lila-openingexplorer /usr/local/bin/
COPY --from=builder /lila-openingexplorer/target/release/import-lichess /usr/local/bin/
ENTRYPOINT ["/usr/local/bin/lila-openingexplorer"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Usage

### Run server

1. Install recent stable Rust ([rustup](https://rustup.rs/) recommended).
1. Install Rust ([rustup](https://rustup.rs/) recommended).

2. Set some environment variables used at build time: `set -a && source .env && set +a`
2. Optionally set some environment variables used at build time: `set -a && source .env && set +a`

3. Build the server and view available options:

Expand Down
4 changes: 4 additions & 0 deletions lila-openingexplorer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ tower-http = { version = "0.6", features = ["set-header"] }
quickcheck = "1"
iai = "0.1"

[features]
default = []
lto = ["rocksdb/lto"]

[[bench]]
name = "benches"
harness = false
Expand Down

0 comments on commit 21d2c41

Please sign in to comment.