diff --git a/.env b/.env deleted file mode 100644 index a343b2ae..00000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -JEMALLOC_SYS_WITH_MALLOC_CONF=abort_conf:true,background_thread:true,metadata_thp:auto,dirty_decay_ms:30000,muzzy_decay_ms:30000 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..f9f07c1e --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index d9553fb5..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Test - -on: [push, pull_request] - -jobs: - test: - runs-on: ubuntu-latest - steps: - - run: sudo apt-get update && sudo apt-get install -y valgrind liburing-dev - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - run: cargo test - - run: cargo bench - - run: cargo test --manifest-path import-pgn/Cargo.toml diff --git a/Cargo.toml b/Cargo.toml index c52bce80..7e4f8541 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,5 @@ members = [ resolver = "2" [profile.release] -lto = true +lto = "fat" +strip = "debuginfo" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..db188f40 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index b89a3f4c..1de0077d 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/lila-openingexplorer/Cargo.toml b/lila-openingexplorer/Cargo.toml index f74b041d..1e0ed6a2 100644 --- a/lila-openingexplorer/Cargo.toml +++ b/lila-openingexplorer/Cargo.toml @@ -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