doc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/usr/bin/env bash
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # doc — renders API documentation.
  12. # When using a nightly toolchain, this script will automatically enables the use
  13. # of some unstable niceties, like the `doc_cfg` annotations to indicate in the
  14. # docs what features must be enabled to use an item.
  15. #
  16. # CI always uses a nightly toolchain to run this script. To use one locally:
  17. #
  18. # $ RUSTUP_TOOLCHAIN=nightly bin/doc
  19. #
  20. set -euo pipefail
  21. cd "$(dirname "$0")/.."
  22. . misc/shlib/shlib.bash
  23. RUSTDOCFLAGS+=" -D warnings "
  24. if [[ $(cargo -V) = *nightly* ]]; then
  25. RUSTDOCFLAGS+=" --cfg nightly_doc_features"
  26. fi
  27. export RUSTDOCFLAGS
  28. target=${CARGO_TARGET_DIR:-target}
  29. cargo doc --all-features "$@"
  30. crates=$(cargo metadata --format-version=1 \
  31. | jq -r -f misc/doc/crates.jq --arg pwd "$(pwd)")
  32. # Create a nice homepage for the docs. It's awful that we have to copy the
  33. # HTML template like this, but the upstream issue [0] that would resolve this is
  34. # now five years old and doesn't look close to resolution.
  35. # [0]: https://github.com/rust-lang/cargo/issues/739
  36. cat > "$target"/doc/index.html <<EOF
  37. <!DOCTYPE html>
  38. <html lang="en">
  39. <head>
  40. <meta charset="utf-8">
  41. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  42. <meta name="generator" content="rustdoc">
  43. <meta name="description" content="API documentation for Materialize.">
  44. <meta name="keywords" content="rust, rustlang, rust-lang, materialize">
  45. <title>Materialize - Rust</title>
  46. <link rel="preload" as="font" type="font/woff2" crossorigin href="SourceSerif4-Regular.ttf.woff2">
  47. <link rel="preload" as="font" type="font/woff2" crossorigin href="FiraSans-Regular.woff2">
  48. <link rel="preload" as="font" type="font/woff2" crossorigin href="FiraSans-Medium.woff2">
  49. <link rel="preload" as="font" type="font/woff2" crossorigin href="SourceCodePro-Regular.ttf.woff2">
  50. <link rel="preload" as="font" type="font/woff2" crossorigin href="SourceSerif4-Bold.ttf.woff2">
  51. <link rel="preload" as="font" type="font/woff2" crossorigin href="SourceCodePro-Semibold.ttf.woff2">
  52. <link rel="stylesheet" type="text/css" href="normalize.css">
  53. <link rel="stylesheet" type="text/css" href="rustdoc.css" id="mainThemeStyle">
  54. <link rel="stylesheet" type="text/css" href="ayu.css" disabled>
  55. <link rel="stylesheet" type="text/css" href="dark.css" disabled>
  56. <link rel="stylesheet" type="text/css" href="light.css" id="themeStyle">
  57. <script id="default-settings" ></script><script src="storage.js"></script><script src="crates.js"></script><script defer src="main.js"></script>
  58. <noscript>
  59. <link rel="stylesheet" href="noscript.css">
  60. </noscript>
  61. <link rel="alternate icon" type="image/png" href="favicon-16x16.png">
  62. <link rel="alternate icon" type="image/png" href="favicon-32x32.png">
  63. <link rel="icon" type="image/svg+xml" href="favicon.svg">
  64. </head>
  65. <body class="rustdoc mod crate">
  66. <!--[if lte IE 11]>
  67. <div class="warning">This old browser is unsupported and will most likely display funky things.</div>
  68. <![endif]-->
  69. <nav class="mobile-topbar">
  70. <button class="sidebar-menu-toggle">&#9776;</button>
  71. <a class="sidebar-logo" href="index.html">
  72. <div class="logo-container"><img class="rust-logo" src="rust-logo.svg" alt="logo"></div>
  73. </a>
  74. <h2 class="location"></h2>
  75. </nav>
  76. <nav class="sidebar">
  77. <a class="sidebar-logo" href="index.html">
  78. <div class="logo-container"><img class="rust-logo" src="rust-logo.svg" alt="logo"></div>
  79. </a>
  80. <div class="sidebar-elems">
  81. <div id="sidebar-vars" data-name="materialize" data-ty="root" data-relpath=""></div>
  82. <script>
  83. addEventListener("DOMContentLoaded", function () {
  84. initSidebarItems({});
  85. });
  86. </script>
  87. </div>
  88. </nav>
  89. <main>
  90. <div class="width-limiter">
  91. <div class="sub-container">
  92. <a class="sub-logo-container" href="index.html"><img class="rust-logo" src="rust-logo.svg" alt="logo"></a>
  93. <nav class="sub">
  94. <div class="theme-picker hidden">
  95. <button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="22" height="22" alt="Pick another theme!" src="brush.svg"></button>
  96. <div id="theme-choices" role="menu"></div>
  97. </div>
  98. <form class="search-form">
  99. <div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="wheel.svg"></a></div>
  100. </form>
  101. </nav>
  102. </div>
  103. <section id="main-content" class="content">
  104. <h1 class='fqn'>
  105. <span class='in-band'>Materialize documentation</span>
  106. </h1>
  107. <p>This is the home of Materialize's internal API documentation.</p>
  108. <h2>Important crates</h2>
  109. <table>
  110. $crates
  111. </table>
  112. </section>
  113. <section id="search" class="content hidden"></section>
  114. </div>
  115. </main>
  116. <div id="rustdoc-vars" data-root-path="." data-current-crate="materialize" data-resource-suffix="" data-themes="ayu,dark,light"></div>
  117. </body>
  118. </html>
  119. EOF
  120. # Make the logo link to the nice homepage we just created. Otherwise it just
  121. # links to the root of whatever crate you happen to be looking at.
  122. cat >> "$target"/doc/main.js <<EOF
  123. ;
  124. for (const logo of document.querySelectorAll("img[alt=logo]")) {
  125. var link = logo.closest("a");
  126. if (link.href != "index.html") {
  127. link.href = "../index.html";
  128. }
  129. }
  130. EOF
  131. echo "Docs are in $target/doc/index.html"