Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 55 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,63 @@
FROM rust:1.95-slim AS base

WORKDIR /analyzer

############################# START SHARED LAYERS #############################

# IMPORTANT: This part of the build is shared between the test-runner and
# analyzer. It takes a relatively large amount of space: 850 MB for the Rust
# toolchain and 40 MB for the local cargo registry. Therefore, it's important
# to keep this in sync between the two images. A slight mismatch in these layers
# would lead to douple the storage requirement on Exercism's servers.

FROM rust:1.95.0 AS build-local-registry

WORKDIR /work
COPY local-registry/Cargo.toml .

RUN <<EOF
set -eux
apt-get update
apt-get install -y gcc openssl cmake
cargo install --locked cargo-local-registry
cargo generate-lockfile
cargo local-registry sync Cargo.lock /local-registry
EOF

# As of April 2026, we need to use the nightly toolchain to get JSON test output
# tracking issue: https://github.com/rust-lang/rust/issues/49359
#
# The official docker image for the nightly Rust toolchain is updated every
# day. We don't want to invalidate the build cache that often, so we pin it
# to a specific hash. To update, go to the following page, then navigate to
# "nightly-slim", select "linux/amd64" and copy the manifest digest.
# https://hub.docker.com/r/rustlang/rust/tags
#
FROM docker.io/rustlang/rust@sha256:3444fefbb69afbff45c0722c8045404c8e7f369c5202e916bd94f665b69f1b1c AS rust-nightly-with-local-registry

# add local registry
COPY --from=build-local-registry /local-registry /local-registry
RUN <<EOF
echo "\
[source.crates-io]
registry = 'sparse+https://index.crates.io/'
replace-with = 'local-registry'

[source.local-registry]
local-registry = '/local-registry'" >> $CARGO_HOME/config.toml
EOF

############################## END SHARED LAYERS ##############################


FROM rust:1.95.0 AS build

WORKDIR /work
COPY . .

RUN cargo build --release

# cargo-local-registry stuff is copied from the test runner
FROM rust:1.95 AS build-cargo-local-registry

# install cargo-local-registry
RUN cargo install --locked cargo-local-registry
# download popular crates to local registry
WORKDIR /local-registry
COPY local-registry/* ./
RUN cargo generate-lockfile && cargo local-registry --sync Cargo.lock .

FROM rust:1.95-slim

WORKDIR /opt/analyzer
FROM rust-nightly-with-local-registry

RUN rustup component add clippy

COPY ./bin/run.sh ./bin/
COPY --from=base /analyzer/target/release/rust-analyzer ./bin/rust-analyzer
COPY --from=build-cargo-local-registry /local-registry local-registry/
# configure local-registry
RUN echo '[source.crates-io]\n\
registry = "https://github.com/rust-lang/crates.io-index"\n\
replace-with = "local-registry"\n\
\n\
[source.local-registry]\n\
local-registry = "/opt/analyzer/local-registry/"\n' >> $CARGO_HOME/config.toml

WORKDIR /opt/analyzer
COPY --from=build /work/target/release/rust-analyzer bin/
COPY bin/run.sh bin/
ENTRYPOINT ["bin/run.sh"]
26 changes: 14 additions & 12 deletions local-registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
[package]
name = "dummy_package"
version = "0.1.0"
edition = "2021"

[lib]
path = "dummy.rs"

# IMPORTANT: These dependencies should be kept in sync with the ones at
# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml
# https://github.com/exercism/rust-analyzer/blob/main/local-registry/Cargo.toml
#
# Some crates are used by a large number of solutions. For example, when a crate
# is required or already included in the exercise skeleton. For those crates,
# we should *never* drop support for a given major version. We can continue to
# support old and new versions by giving the old ones an alias. The downside is
# an increase in the size of the local registry.
# we should NEVER drop support for a given major version. They have been marked
# with a "# pin" comment. We can continue to support old and new versions by
# giving the old ones an alias. An example is the rand_09 crate below.
#
[dependencies]
anyhow = "1.0.102" # pin
Expand Down Expand Up @@ -119,3 +111,13 @@ unzip-n = "0.1.4"
uuid = "1.23.1"
voca_rs = "1.15.2"
xvii = "0.4.0"

# The following is only needed so the Cargo.toml defines a valid package.

[package]
name = "dummy_package"
version = "0.1.0"
edition = "2024"

[lib]
path = "/dev/null"
Empty file removed local-registry/dummy.rs
Empty file.
2 changes: 1 addition & 1 deletion snippets/two_comments/expected_analysis.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"comment": "rust.general.clippy",
"params": {
"clippy_msg": "warning: unneeded `return` statement\n --> src/lib.rs:2:5\n |\n2 | return --x;\n | ^^^^^^^^^^\n |\n = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#needless_return\n = note: `#[warn(clippy::needless_return)]` on by default\nhelp: remove `return`\n |\n2 - return --x;\n2 + --x\n |"
"clippy_msg": "warning: unneeded `return` statement\n --> src/lib.rs:2:5\n |\n2 | return --x;\n | ^^^^^^^^^^\n |\n = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return\n = note: `#[warn(clippy::needless_return)]` on by default\nhelp: remove `return`\n |\n2 - return --x;\n2 + --x\n |"
},
"type": "informative"
}
Expand Down
Loading