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
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ WORKDIR /app
FROM chef AS planner
COPY Cargo.toml ./Cargo.toml
COPY Cargo.lock ./Cargo.lock
COPY build.rs ./build.rs
COPY src ./src
COPY templates ./templates
RUN cargo chef prepare --recipe-path recipe.json
Expand All @@ -25,6 +26,7 @@ RUN cargo chef cook --profile ${CARGO_PROFILE} --recipe-path recipe.json
# Copy sources and build the application binary
COPY Cargo.toml ./Cargo.toml
COPY Cargo.lock ./Cargo.lock
COPY build.rs ./build.rs
COPY src ./src
COPY templates ./templates
RUN cargo build --profile ${CARGO_PROFILE} --bin cryptify
Expand Down
31 changes: 31 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
fn main() {
println!("cargo:rerun-if-changed=Cargo.lock");

let lock = std::fs::read_to_string("Cargo.lock").expect("Cargo.lock not readable");
let version = lock
.split("[[package]]")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Code review] Splitting Cargo.lock on the literal [[package]] is fragile if a future lockfile format ever includes that substring inside a quoted string (no such case today). A tiny TOML parse (or cargo_metadata) would be safer; not blocking.

.find_map(|block| {
let mut name = None;
let mut ver = None;
for line in block.lines() {
if let Some(rest) = line.strip_prefix("name = \"") {
name = rest.strip_suffix('"');
}
if let Some(rest) = line.strip_prefix("version = \"") {
ver = rest.strip_suffix('"');
}
}
if name == Some("pg-core") {
ver
} else {
None
}
})
.expect(
"pg-core entry not found in Cargo.lock — PG_CORE_VERSION feeds the \
X-PostGuard mail header that the Outlook add-in's OnMessageRead \
launch event filters on (see src/email.rs::XPostGuard).",
);

println!("cargo:rustc-env=PG_CORE_VERSION={}", version);
}
Loading