From 305973dd6c8f9875ff4b118d622554e1842efc47 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Tue, 26 Mar 2024 14:25:52 +0100 Subject: [PATCH 1/6] Add scss to editorconfig --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index 56606a821..ffcea9382 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,6 +1,6 @@ root = true -[*.{rs,html,js}] +[*.{rs,html,js,scss}] end_of_line = lf charset = utf-8 trim_trailing_whitespace = true From 57297d9d75b11bf9095d13d117726082fb5b33ae Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Mon, 25 Mar 2024 21:04:47 +0100 Subject: [PATCH 2/6] Bind static files into docker container --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index ce503de9c..790ea6140 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,6 +16,7 @@ services: - "/var/run/docker.sock:/var/run/docker.sock" - ".rustwide-docker:/opt/docsrs/rustwide" - "cratesio-index:/opt/docsrs/prefix/crates.io-index" + - "./static:/opt/docsrs/static:ro" environment: DOCSRS_RUSTWIDE_WORKSPACE: /opt/docsrs/rustwide DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@db From 2a7fa2bb2a8038e2bf05af64672e06ac32614a51 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Tue, 26 Mar 2024 14:31:15 +0100 Subject: [PATCH 3/6] Optimize and reduce debuginfo of dependencies in debug builds Unless you're doing clean builds all the time, having optimized dependencies and reducing the debuginfo generated for them is faster because it makes the linker do less work. --- Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 08500bd24..6484f147c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -132,8 +132,9 @@ aws-smithy-runtime = {version = "1.0.1", features = ["client", "test-util"]} aws-smithy-http = "0.60.0" indoc = "2.0.0" -[profile.dev.package.sqlx-macros] +[profile.dev.package."*"] opt-level = 2 +debug = "line-tables-only" [build-dependencies] time = "0.3" From 2db77037e01eee40e080c53989a8650a56519f84 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Tue, 26 Mar 2024 14:57:52 +0100 Subject: [PATCH 4/6] Build docker image in dev profile for docker-compose This improves turnaround speed when locally testing changes that require rebuilding the docker image. --- docker-compose.yml | 3 +++ dockerfiles/Dockerfile | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 790ea6140..6bad85bf3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,9 @@ services: build: context: . dockerfile: ./dockerfiles/Dockerfile + args: + PROFILE: dev + PROFILE_DIR: debug platform: "linux/amd64" depends_on: - db diff --git a/dockerfiles/Dockerfile b/dockerfiles/Dockerfile index 2ece0578d..dba85344b 100644 --- a/dockerfiles/Dockerfile +++ b/dockerfiles/Dockerfile @@ -36,7 +36,9 @@ RUN mkdir -p src/bin && \ echo "fn main() {}" > build.rs RUN cargo fetch -RUN cargo build --release + +ARG PROFILE=release +RUN cargo build --profile=$PROFILE # Dependencies are now cached, copy the actual source code and do another full # build. The touch on all the .rs files is needed, otherwise cargo assumes the @@ -54,7 +56,7 @@ COPY assets assets/ COPY .sqlx .sqlx/ COPY migrations migrations/ -RUN cargo build --release +RUN cargo build --profile=$PROFILE ###################### # Web server stage # @@ -69,7 +71,8 @@ RUN apt-get update \ tini \ && rm -rf /var/lib/apt/lists/* -COPY --from=build /build/target/release/cratesfyi /usr/local/bin +ARG PROFILE_DIR=release +COPY --from=build /build/target/$PROFILE_DIR/cratesfyi /usr/local/bin COPY static /srv/docsrs/static COPY templates /srv/docsrs/templates COPY vendor /srv/docsrs/vendor @@ -96,7 +99,8 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ RUN mkdir -p /opt/docsrs/prefix -COPY --from=build /build/target/release/cratesfyi /usr/local/bin +ARG PROFILE_DIR=release +COPY --from=build /build/target/$PROFILE_DIR/cratesfyi /usr/local/bin COPY static /opt/docsrs/static COPY templates /opt/docsrs/templates COPY dockerfiles/entrypoint.sh /opt/docsrs/ From 62d63804144a4d94fbafc95c784b86593d431df0 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Tue, 26 Mar 2024 14:59:12 +0100 Subject: [PATCH 5/6] Use mold for faster linking in docker build --- dockerfiles/Dockerfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dockerfiles/Dockerfile b/dockerfiles/Dockerfile index dba85344b..f9ec2c4ad 100644 --- a/dockerfiles/Dockerfile +++ b/dockerfiles/Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu:22.04 AS build # Install packaged dependencies RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ build-essential git curl cmake gcc g++ pkg-config libmagic-dev \ - libssl-dev zlib1g-dev ca-certificates + libssl-dev zlib1g-dev ca-certificates mold clang # Install the stable toolchain with rustup RUN curl https://sh.rustup.rs >/tmp/rustup-init && \ @@ -22,6 +22,11 @@ RUN curl https://sh.rustup.rs >/tmp/rustup-init && \ /tmp/rustup-init -y --no-modify-path --default-toolchain stable --profile minimal ENV PATH=/root/.cargo/bin:$PATH +# Configure linking to use mold instead for speed (need to use clang because gcc +# is too old on this image) +ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=clang +ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS=-Clink-arg=-fuse-ld=mold + # Build the dependencies in a separate step to avoid rebuilding all of them # every time the source code changes. This takes advantage of Docker's layer # caching, and it works by copying the Cargo.{toml,lock} with dummy source code From 2825b6e289c6cbdbaa7fe82bbd337f9d78658226 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Fri, 1 Mar 2024 12:49:13 +0100 Subject: [PATCH 6/6] Introduce warning topbar menu, allow following crates to see warnings for --- static/warnings.js | 120 +++++++++++++++++++++++++++++++ templates/base.html | 1 + templates/header/topbar_end.html | 2 + templates/header/warnings.html | 7 ++ templates/rustdoc/body.html | 1 + templates/style/_navbar.scss | 16 +++++ 6 files changed, 147 insertions(+) create mode 100644 static/warnings.js create mode 100644 templates/header/warnings.html diff --git a/static/warnings.js b/static/warnings.js new file mode 100644 index 000000000..3be657d38 --- /dev/null +++ b/static/warnings.js @@ -0,0 +1,120 @@ +(function() { + function load(key, def = null) { + const value = window.localStorage.getItem(key) + if (value) { + try { + return JSON.parse(value) + } catch (ex) { + console.error(`Failed loading ${key} from local storage`, ex) + return def + } + } else { + return def + } + } + + function store(key, value) { + window.localStorage.setItem(key, JSON.stringify(value)) + } + + function create(tagName, attrs = {}, children = [], listeners = {}) { + const el = document.createElement(tagName) + for (const key of Object.keys(attrs)) { + if (typeof attrs[key] === 'object') { + for (const subkey of Object.keys(attrs[key])) { + el[key].setProperty(subkey, attrs[key][subkey]) + } + } else { + el.setAttribute(key, attrs[key]) + } + } + el.append(...children) + for (const key of Object.keys(listeners)) { + el.addEventListener(key, listeners[key]) + } + return el + } + + + if (!load('docs-rs-warnings-enabled', false)) { + return + } + + const parentEl = document.getElementById('warnings-menu-parent') + parentEl.removeAttribute('hidden') + + const current = JSON.parse(document.getElementById("crate-metadata")?.innerText || null) + + const menuEl = document.getElementById('warnings-menu') + + const followed = load('docs-rs-warnings-followed', []) + + function update() { + const children = [] + + if (followed.length > 0) { + children.push( + create('div', { class: 'pure-g' }, [ + create('div', { class: 'pure-u-1' }, [ + create('ul', { class: 'pure-menu-list', style: { width: '100%' } }, [ + create('li', { class: 'pure-menu-heading' }, [ + create('b', {}, ['Followed crates']), + ]), + ...followed.map(name => ( + create('li', { class: 'pure-menu-item followed' }, [ + create('a', { class: 'pure-menu-link', href: `/${name}` }, [ + name, + ]), + create('a', { class: 'pure-menu-link remove', href: '#' }, ['🗙'], { + click: (ev) => { + const index = followed.indexOf(name) + followed.splice(index, 1) + store('docs-rs-warnings-followed', followed) + update() + }, + }), + ]) + )), + ]), + ]), + ]), + ) + } + + if (current && !followed.includes(current.name)) { + children.push( + create('div', { class: 'pure-g' }, [ + create('div', { class: 'pure-u-1' }, [ + create('ul', { class: 'pure-menu-list', style: { width: '100%' } }, [ + create('li', { class: 'pure-menu-item' }, [ + create('a', { class: 'pure-menu-link', href: '#' }, [ + "Follow ", + create('b', {}, [current.name]), + ], { + click: () => { + const index = followed.findIndex((name) => name > current.name) + if (index >= 0) { + followed.splice(index, 0, current.name) + } else { + followed.push(current.name) + } + store('docs-rs-warnings-followed', followed) + update() + } + }), + ]), + ]), + ]), + ]), + ) + } + + for (const child of children.slice(0, -1)) { + child.classList.add('menu-item-divided') + } + + menuEl.replaceChildren(...children) + } + + update() +})() diff --git a/templates/base.html b/templates/base.html index 6f3fb9ba8..779c3b9a8 100644 --- a/templates/base.html +++ b/templates/base.html @@ -22,6 +22,7 @@ + diff --git a/templates/header/topbar_end.html b/templates/header/topbar_end.html index 1e3f1cf2d..8a4f5e9ec 100644 --- a/templates/header/topbar_end.html +++ b/templates/header/topbar_end.html @@ -4,6 +4,8 @@ {# The global alert, if there is one #} {% include "header/global_alert.html" -%} + {% include "header/warnings.html" -%} +
    {# The Rust dropdown menu diff --git a/templates/header/warnings.html b/templates/header/warnings.html new file mode 100644 index 000000000..4c9d173a8 --- /dev/null +++ b/templates/header/warnings.html @@ -0,0 +1,7 @@ + diff --git a/templates/rustdoc/body.html b/templates/rustdoc/body.html index edf35f4ad..8fe1434eb 100644 --- a/templates/rustdoc/body.html +++ b/templates/rustdoc/body.html @@ -1,4 +1,5 @@ + {# see comment in ../storage-change-detection.html for details #} diff --git a/templates/style/_navbar.scss b/templates/style/_navbar.scss index db95ef4cc..d975d982b 100644 --- a/templates/style/_navbar.scss +++ b/templates/style/_navbar.scss @@ -362,6 +362,22 @@ div.nav-container { } } } + + #warnings-menu { + .followed { + display: flex; + align-items: center; + :first-child { + flex: auto; + } + } + .remove { + padding: 0 .5em; + &:hover { + color: var(--color-error); + } + } + } } #nav-search, #nav-sort {