# syntax=docker/dockerfile:1 # # djvu-rs 0.42.0 (Mikhail Matyushkin; MIT, written from the DjVu v3 # specification, no GPL code) compiled to WebAssembly for johnmcm.com's # /djvu-to-pdf and /open-file/djvu: this folder's small crate (src/lib.rs) # re-exports djvu-rs's own viewer bindings and adds PDF export and # bookmarks, built with wasm-pack for ES-module workers with WebAssembly # SIMD on. The Rust image is pinned by digest, djvu-rs by exact version, the # crates by Cargo.lock (generated by the first build and kept here). # # ./build.ps1 (or) docker build --target export --output type=local,dest=dist . ARG RUST_IMAGE=rust:1.89-bookworm@sha256:948f9b08a66e7fe01b03a98ef1c7568292e07ec2e4fe90d88c07bb14563c84ff FROM ${RUST_IMAGE} AS build RUN rustup target add wasm32-unknown-unknown \ && cargo install --locked wasm-pack --version 0.13.1 # djvu-rs itself, from crates.io (checked against the checksum Cargo.lock # records), with two patches: the PDF's invisible text layer in Unicode, and # links between pages that work (patches/pdf-text-and-links.patch, using # font/glyphless.ttf); then links and bookmarks that name a page by number, # by component name or by a step from the current page, resolved against the # whole book and shifted for a page range (patches/link-scope.patch, whose # unit tests run here). Cargo.toml's [patch.crates-io] points the build at # this copy. ARG DJVU_RS_VERSION=0.42.0 ARG DJVU_RS_SHA256=c39f7585887a2d8a22e49593e47c2bf679cf302403935f8868afc5acad39b759 WORKDIR /src COPY patches/ /patches/ COPY font/glyphless.ttf /patches/ RUN curl -fsSL -o djvu-rs.crate https://crates.io/api/v1/crates/djvu-rs/${DJVU_RS_VERSION}/download \ && echo "${DJVU_RS_SHA256} djvu-rs.crate" | sha256sum -c - \ && tar xzf djvu-rs.crate && mv djvu-rs-${DJVU_RS_VERSION} djvu-rs \ && cd djvu-rs && sed 's/\r$//' /patches/pdf-text-and-links.patch | patch -p1 \ && sed 's/\r$//' /patches/link-scope.patch | patch -p1 \ && cp /patches/glyphless.ttf src/pdf/glyphless.ttf # The link resolver's own tests, on a scratch copy: djvu-rs's PDF test module # no longer compiles against the text-layer patch (it calls the Helvetica # font helper that patch replaced), so it is left out there only. RUN cp -r djvu-rs /tmp/test && cd /tmp/test \ && sed -i 's/^mod tests;$/mod tests {}/' src/pdf/mod.rs \ && cargo test --lib --no-default-features --features std,pdf link_scope_tests \ && rm -rf /tmp/test WORKDIR /djvu COPY Cargo.toml ./ # The lockfile from the first build, when there is one. COPY Cargo.lock* ./ COPY src/ src/ ENV RUSTFLAGS="-C target-feature=+simd128" RUN wasm-pack build --release --target web --out-name djvu --out-dir /out/pkg # djvu-rs's licence, from the crate. RUN mkdir -p /out/dist \ && cp /out/pkg/djvu.js /out/pkg/djvu_bg.wasm Cargo.lock /out/dist/ \ && cp /src/djvu-rs/LICENSE /out/dist/LICENSE \ && sha256sum /out/dist/* FROM scratch AS export COPY --from=build /out/dist/ /