Skip to content

Commit 4fef336

Browse files
committed
[hermes] In dev, install prebuilts in target
This allows developers to isolate their development from their use of `cargo hermes verify` globally. It also makes development slightly easier to integrate with Docker, as `cargo run setup`, when run in the container, doesn't try to write to paths that aren't writeable (this is specifically a problem since we re-define the UID of the user in the container in order to match the external UID, making them not root in the container, but thus making them not have write permissions to root's home directory). gherrit-pr-id: Gzjx2m23qp7ycaxvr2hvvsspjslbysoix
1 parent 9252871 commit 4fef336

16 files changed

Lines changed: 73 additions & 51 deletions

File tree

hermes/Dockerfile

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
FROM ubuntu:24.04 AS base
22

3-
# Relocate toolchains so non-root developers can access and write to them when mapping UIDs
3+
# Relocate toolchains so non-root developers can access and write to them when
4+
# mapping UIDs.
45
ENV RUSTUP_HOME=/opt/rustup \
56
CARGO_HOME=/opt/cargo \
67
ELAN_HOME=/opt/elan \
78
PATH="/opt/cargo/bin:/opt/elan/bin:${PATH}"
89

9-
# Install build dependencies, Rust, and Lean
1010
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y git curl build-essential pkg-config libssl-dev && \
1111
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path && \
1212
rm -rf /var/lib/apt/lists/*
1313

14-
# Install elan (Lean toolchain manager)
14+
# Charon strictly requires a specific nightly compiler version to execute.
15+
# FIXME: Extract this version string dynamically from `src/setup.rs` in the future.
16+
RUN rustup toolchain install --no-self-update nightly-2026-02-07 --profile minimal
17+
18+
# Install elan (Lean toolchain manager).
1519
RUN curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh -s -- -y --no-modify-path
1620

1721
# Prepare a globally writable cache directory to hold both the integration test
@@ -21,44 +25,17 @@ RUN curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -
2125
RUN mkdir -p /cache && chmod 777 /cache && \
2226
chmod -R a+rwX /opt/rustup /opt/cargo /opt/elan
2327

24-
# Direct Hermes tests to write ephemeral integration targets here to leverage overlayfs
28+
# Direct Hermes tests to write ephemeral integration targets here to leverage
29+
# overlayfs.
2530
ENV HERMES_INTEGRATION_TARGET_DIR=/cache/hermes_target
2631
WORKDIR /workspace
2732

28-
# Copy vendored requirements
29-
COPY .cargo .cargo
30-
COPY vendor vendor
31-
32-
ENV __ZEROCOPY_LOCAL_DEV="1"
33+
FROM base AS dev
3334

34-
# Copy only the hermes crate logic
35-
COPY Cargo.toml Cargo.toml
36-
COPY build.rs build.rs
37-
COPY src src
38-
# Since Cargo.toml explicitly declares [[test]] "integration", this file must exist for Cargo to parse it.
39-
COPY tests/integration.rs tests/integration.rs
40-
# Copy tools because they are part of the workspace members
35+
COPY testdata testdata
4136
COPY tools tools
4237

43-
# Download and verify the required versions of Charon and Aeneas.
44-
RUN cargo run --bin cargo-hermes setup && \
45-
rm -rf /workspace/target /opt/cargo/registry /opt/cargo/git
46-
47-
# Charon strictly requires a specific nightly compiler version to execute.
48-
# FIXME: Extract this version string dynamically from `src/setup.rs` in the future.
49-
RUN rustup toolchain install nightly-2026-02-07 --profile minimal && \
50-
chmod -R a+rwX /opt/rustup /opt/cargo /opt/elan
51-
52-
# To pre-build Mathlib for local development, we run a fast dummy test. We don't
53-
# use this in CI because copying the multiple GB produced in this image is
54-
# slower in CI than just re-building from scratch.
55-
FROM base AS dev
56-
COPY tests/fixtures/syntax_error tests/fixtures/syntax_error
57-
RUN cargo test --test integration -- syntax_error && \
58-
chmod -R a+rwX /cache
38+
# Download Lean/Elan and pre-build the Mathlib cache and Aeneas standard library.
39+
RUN ./tools/prebuild_lean_libs.sh
5940

60-
# Any `/workspace/target` generated here will be shadowed by the host's bind
61-
# mount, so removing it is purely to reduce image size slightly before
62-
# shadowing. Because of this shadowing, there would be no benefit to keeping
63-
# it.
64-
RUN rm -rf /workspace/target
41+
RUN chmod -R a+rwX /cache /opt/rustup /opt/cargo /opt/elan

hermes/src/setup.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,15 @@ pub struct Toolchain {
138138
impl Toolchain {
139139
/// Resolves the toolchain manager and acquires a shared lock.
140140
pub fn resolve() -> Result<Self> {
141-
let home =
142-
dirs::home_dir().ok_or_else(|| anyhow::anyhow!("Could not find home directory"))?;
141+
let home = if std::env::var("__ZEROCOPY_LOCAL_DEV").is_ok() {
142+
std::path::PathBuf::from(
143+
std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string()),
144+
)
145+
.join("target")
146+
.join("hermes-home")
147+
} else {
148+
dirs::home_dir().ok_or_else(|| anyhow::anyhow!("Could not find home directory"))?
149+
};
143150
let platform = Platform::detect()?;
144151
let aeneas_hash = platform.expected_archive_hash();
145152

hermes/tests/fixtures/allow_sorry_fallbacks/expected.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@
6969
59 │ /// ```
7070
╰────
7171

72-
Error: Lean verification failed. Consider running `cargo run generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.
72+
Error: Lean verification failed. Consider running `cargo hermes generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Error: Charon version mismatch.
22
Expected: 0.1.174
33
Found: 0.0.0
4-
Please run `cargo run setup` to install the correct version.
4+
Please run `cargo hermes setup` to install the correct version.

hermes/tests/fixtures/const_generics/expected.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
9 │ /// ```
99
╰────
1010

11-
Error: Lean verification failed. Consider running `cargo run generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.
11+
Error: Lean verification failed. Consider running `cargo hermes generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.

hermes/tests/fixtures/diagnostic_mapping/expected.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636
42 │ /// ```
3737
╰────
3838

39-
Error: Lean verification failed. Consider running `cargo run generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.
39+
Error: Lean verification failed. Consider running `cargo hermes generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.

hermes/tests/fixtures/edge_cases_logic/test_5_4_std_types/expected.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ Note: Expected a function because this term is being applied to the argument
2121
Std.U32
2222

2323
Hint: The identifier `Vec` is unknown, and Lean's `autoImplicit` option causes an unknown identifier to be treated as an implicitly bound variable with an unknown type. However, the unknown type cannot be a function, and a function is what Lean expects here. This is often the result of a typo or a missing `import` or `open` statement.
24-
Error: Lean verification failed. Consider running `cargo run generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.
24+
Error: Lean verification failed. Consider running `cargo hermes generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.

hermes/tests/fixtures/edge_cases_mut_refs/test_3_3_ret_mut/expected.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ Note: Expected a function because this term is being applied to the argument
2828
Std.U32
2929

3030
Hint: The identifier `Vec` is unknown, and Lean's `autoImplicit` option causes an unknown identifier to be treated as an implicitly bound variable with an unknown type. However, the unknown type cannot be a function, and a function is what Lean expects here. This is often the result of a typo or a missing `import` or `open` statement.
31-
Error: Lean verification failed. Consider running `cargo run generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.
31+
Error: Lean verification failed. Consider running `cargo hermes generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.

hermes/tests/fixtures/enums_pattern_matching/expected.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
10 │ /// | Enum.B b => b
1313
╰────
1414

15-
Error: Lean verification failed. Consider running `cargo run generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.
15+
Error: Lean verification failed. Consider running `cargo hermes generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.

hermes/tests/fixtures/is_valid_verification/expected.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@
9292
29 │ /// ```
9393
╰────
9494

95-
Error: Lean verification failed. Consider running `cargo run generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.
95+
Error: Lean verification failed. Consider running `cargo hermes generate`, iterating on generated `.lean` files, and copying results back to `.rs` files.

0 commit comments

Comments
 (0)