third_party/rust: initialize, add mdbook
As we want to use [mdbook](https://github.com/rust-lang/mdBook) to build
documentation, we now have to pull it into the monorepo, alongside
support for Rust in general.
Testing plan: bazel run //third_party/rust:cargo_bin_mdbook. The CI
should also pick this up now.
Change-Id: I6cf5d02d926bb0de61a5c882828accd35f3a1076
Reviewed-on: https://review.monogon.dev/c/monogon/+/201
Reviewed-by: Leopold Schabel <leo@nexantic.com>
diff --git a/third_party/rust/Cargo.toml b/third_party/rust/Cargo.toml
new file mode 100644
index 0000000..f57f0d0
--- /dev/null
+++ b/third_party/rust/Cargo.toml
@@ -0,0 +1,104 @@
+[package]
+name = "compile_with_bazel"
+version = "0.0.0"
+
+# Mandatory (or Cargo tooling is unhappy)
+[lib]
+path = "fake_lib.rs"
+
+[dependencies]
+mdbook = "0"
+
+[package.metadata.raze]
+workspace_path = "//third_party/rust/cargo"
+package_aliases_dir = "."
+targets = [
+ "x86_64-unknown-linux-gnu",
+]
+genmode = "Remote"
+
+[package.metadata.raze.crates.handlebars.'4.0.1']
+data_dependencies = [
+ "src/grammar.pest",
+]
+
+[package.metadata.raze.crates.mdbook.'0.4.10']
+data_dependencies = [
+ "src/theme/playground_editor/ace.js",
+ "src/theme/playground_editor/editor.js",
+ "src/theme/playground_editor/mode-rust.js",
+ "src/theme/playground_editor/theme-dawn.js",
+ "src/theme/playground_editor/theme-tomorrow_night.js",
+
+ "src/theme/fonts/OPEN-SANS-LICENSE.txt",
+ "src/theme/fonts/SOURCE-CODE-PRO-LICENSE.txt",
+ "src/theme/fonts/fonts.css",
+ "src/theme/fonts/open-sans-v17-all-charsets-300.woff2",
+ "src/theme/fonts/open-sans-v17-all-charsets-300italic.woff2",
+ "src/theme/fonts/open-sans-v17-all-charsets-600.woff2",
+ "src/theme/fonts/open-sans-v17-all-charsets-600italic.woff2",
+ "src/theme/fonts/open-sans-v17-all-charsets-700.woff2",
+ "src/theme/fonts/open-sans-v17-all-charsets-700italic.woff2",
+ "src/theme/fonts/open-sans-v17-all-charsets-800.woff2",
+ "src/theme/fonts/open-sans-v17-all-charsets-800italic.woff2",
+ "src/theme/fonts/open-sans-v17-all-charsets-italic.woff2",
+ "src/theme/fonts/open-sans-v17-all-charsets-regular.woff2",
+ "src/theme/fonts/source-code-pro-v11-all-charsets-500.woff2",
+
+ "src/theme/searcher/elasticlunr.min.js",
+ "src/theme/searcher/mark.min.js",
+ "src/theme/searcher/searcher.js",
+
+ "src/theme/ayu-highlight.css",
+ "src/theme/book.js",
+ "src/theme/clipboard.min.js",
+ "src/theme/favicon.png",
+ "src/theme/favicon.svg",
+ "src/theme/head.hbs",
+ "src/theme/header.hbs",
+ "src/theme/highlight.css",
+ "src/theme/highlight.js",
+ "src/theme/index.hbs",
+ "src/theme/redirect.hbs",
+ "src/theme/tomorrow-night.css",
+
+ "src/theme/css/chrome.css",
+ "src/theme/css/general.css",
+ "src/theme/css/print.css",
+ "src/theme/css/variables.css",
+
+ "src/theme/FontAwesome/css/font-awesome.min.css",
+ "src/theme/FontAwesome/fonts/FontAwesome.otf",
+ "src/theme/FontAwesome/fonts/fontawesome-webfont.eot",
+ "src/theme/FontAwesome/fonts/fontawesome-webfont.svg",
+ "src/theme/FontAwesome/fonts/fontawesome-webfont.ttf",
+ "src/theme/FontAwesome/fonts/fontawesome-webfont.woff",
+ "src/theme/FontAwesome/fonts/fontawesome-webfont.woff2",
+]
+# Generate the binary target alias //third_party/rust:cargo_bin_mdbook.
+extra_aliased_targets = [
+ "cargo_bin_mdbook"
+]
+# We end up linking mdbook into a binary. rustc, when doing that, calls gcc as
+# a linker (probably because cc-rs?).
+#
+# On our build container, the gcc used as a linker is /usr/bin/gcc. This gcc
+# then attempts to call its corresponding system ld, expecting it to be on
+# PATH. However, rules_rust hermeticizes the build to the point where PATH is
+# totally stripped out. Here, we add back /usr/bin back as the sole PATH
+# element, thereby making 'ld' resolvable agan by /usr/bin/gcc.
+#
+# In an ideal world, we would be able to translate Bazel C++ toolchain
+# definitions into Cargo/rustc's build system. These definitions technically
+# contain everything needed to know how to call a toolchain. However, it seems
+# like the current ecosystem of linking C/C++ in Rust is not centralized enough
+# for this to be easily doable, as the responsibility is spread between rustc,
+# Cargo, and third-party crates like cc-rs.
+#
+# For now, this has to do - as long as we don't use Cargo/Rust for secondary
+# operating system tools like mdbook, and not as something directly in the
+# transitive dependency set of building a Metropolis release. This is also why
+# we 'fix' this only for mdbook for now, we don't want to even pretend that
+# this is something that should be used where reproducibility and hermeticity
+# matters.
+additional_env.PATH = "/usr/bin"