Skip to content

Commit

Permalink
Unrolled build for rust-lang#136161
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#136161 - notriddle:typescript, r=GuillaumeGomez

rustdoc: add nobuild typescript checking to our JS

By nobuild, I mean that the type annotations are all [in comments], not in the "native" typescript syntax. This is a bit uglier, but it lets you rapid-prototype without tsc, works with all the native browser debugging tools, and keeps Node out of Rust's bootstrap chain.

[in comments]: https://news.ycombinator.com/item?id=35892250

This pull request mostly just adds ts-ignore annotations and type declarations. To actually take good advantage of typescript, we'll want to "burn down" this pile of unsafe code until we eventually have a version with almost none of these.

This PR also adds tsc to the mingw-check Dockerfile, so that it can't fall out of date like the Closure annotations did.

https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/typescript

r? `@GuillaumeGomez` `@lolbinarycat`
  • Loading branch information
rust-timer authored Jan 29, 2025
2 parents 61cc3e5 + d94b64d commit 4da3a6b
Show file tree
Hide file tree
Showing 11 changed files with 1,658 additions and 682 deletions.
5 changes: 3 additions & 2 deletions src/ci/docker/host-x86_64/mingw-check/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ENV PATH="/node/bin:${PATH}"

# Install es-check
# Pin its version to prevent unrelated CI failures due to future es-check versions.
RUN npm install es-check@6.1.1 eslint@8.6.0 -g
RUN npm install es-check@6.1.1 eslint@8.6.0 typescript@5.7.3 -g

COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh
Expand Down Expand Up @@ -68,4 +68,5 @@ ENV SCRIPT \
es-check es2019 ../src/librustdoc/html/static/js/*.js && \
eslint -c ../src/librustdoc/html/static/.eslintrc.js ../src/librustdoc/html/static/js/*.js && \
eslint -c ../src/tools/rustdoc-js/.eslintrc.js ../src/tools/rustdoc-js/tester.js && \
eslint -c ../src/tools/rustdoc-gui/.eslintrc.js ../src/tools/rustdoc-gui/tester.js
eslint -c ../src/tools/rustdoc-gui/.eslintrc.js ../src/tools/rustdoc-gui/tester.js && \
tsc --project ../src/librustdoc/html/static/js/tsconfig.json
10 changes: 3 additions & 7 deletions src/librustdoc/html/static/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
These JavaScript files are incorporated into the rustdoc binary at build time,
and are minified and written to the filesystem as part of the doc build process.

We use the [Closure Compiler](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler)
We use the [TypeScript Compiler](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html)
dialect of JSDoc to comment our code and annotate params and return types.
To run a check:

./x.py doc library/std
npm i -g google-closure-compiler
google-closure-compiler -W VERBOSE \
build/<YOUR PLATFORM>/doc/{search-index*.js,crates*.js} \
src/librustdoc/html/static/js/{search.js,main.js,storage.js} \
--externs src/librustdoc/html/static/js/externs.js >/dev/null
npm i -g typescript
tsc --project tsconfig.json
270 changes: 0 additions & 270 deletions src/librustdoc/html/static/js/externs.js

This file was deleted.

Loading

0 comments on commit 4da3a6b

Please sign in to comment.