Skip to content

Commit 0177a37

Browse files
committed
Add translation support by mdbook-i18n-helpers to bootstrap
1 parent f5efc3c commit 0177a37

File tree

4 files changed

+197
-16
lines changed

4 files changed

+197
-16
lines changed

Cargo.lock

+151-5
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
337337
checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05"
338338
dependencies = [
339339
"memchr",
340-
"regex-automata 0.3.9",
340+
"regex-automata 0.3.7",
341341
"serde",
342342
]
343343

@@ -2218,6 +2218,21 @@ dependencies = [
22182218
"vcpkg",
22192219
]
22202220

2221+
[[package]]
2222+
name = "line-wrap"
2223+
version = "0.2.0"
2224+
source = "registry+https://github.com/rust-lang/crates.io-index"
2225+
checksum = "dd1bc4d24ad230d21fb898d1116b1801d7adfc449d42026475862ab48b11e70e"
2226+
2227+
[[package]]
2228+
name = "linereader"
2229+
version = "0.4.0"
2230+
source = "registry+https://github.com/rust-lang/crates.io-index"
2231+
checksum = "d921fea6860357575519aca014c6e22470585accdd543b370c404a8a72d0dd1d"
2232+
dependencies = [
2233+
"memchr",
2234+
]
2235+
22212236
[[package]]
22222237
name = "linkchecker"
22232238
version = "0.1.0"
@@ -2226,6 +2241,12 @@ dependencies = [
22262241
"regex",
22272242
]
22282243

2244+
[[package]]
2245+
name = "linked-hash-map"
2246+
version = "0.5.6"
2247+
source = "registry+https://github.com/rust-lang/crates.io-index"
2248+
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
2249+
22292250
[[package]]
22302251
name = "lint-docs"
22312252
version = "0.1.0"
@@ -2362,6 +2383,24 @@ dependencies = [
23622383
"topological-sort",
23632384
]
23642385

2386+
[[package]]
2387+
name = "mdbook-i18n-helpers"
2388+
version = "0.3.2"
2389+
source = "git+https://github.com/dalance/mdbook-i18n-helpers?branch=export_preprocessor#c2c5251481ed779f44b1abe4238916209f995cc8"
2390+
dependencies = [
2391+
"anyhow",
2392+
"chrono",
2393+
"mdbook",
2394+
"polib",
2395+
"pulldown-cmark 0.9.6",
2396+
"pulldown-cmark-to-cmark",
2397+
"regex",
2398+
"semver",
2399+
"serde_json",
2400+
"syntect",
2401+
"textwrap",
2402+
]
2403+
23652404
[[package]]
23662405
name = "measureme"
23672406
version = "11.0.1"
@@ -2650,6 +2689,28 @@ version = "1.19.0"
26502689
source = "registry+https://github.com/rust-lang/crates.io-index"
26512690
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
26522691

2692+
[[package]]
2693+
name = "onig"
2694+
version = "6.4.0"
2695+
source = "registry+https://github.com/rust-lang/crates.io-index"
2696+
checksum = "8c4b31c8722ad9171c6d77d3557db078cab2bd50afcc9d09c8b315c59df8ca4f"
2697+
dependencies = [
2698+
"bitflags 1.3.2",
2699+
"libc",
2700+
"once_cell",
2701+
"onig_sys",
2702+
]
2703+
2704+
[[package]]
2705+
name = "onig_sys"
2706+
version = "69.8.1"
2707+
source = "registry+https://github.com/rust-lang/crates.io-index"
2708+
checksum = "7b829e3d7e9cc74c7e315ee8edb185bf4190da5acde74afd7fc59c35b1f086e7"
2709+
dependencies = [
2710+
"cc",
2711+
"pkg-config",
2712+
]
2713+
26532714
[[package]]
26542715
name = "opener"
26552716
version = "0.6.1"
@@ -2947,6 +3008,29 @@ version = "0.3.30"
29473008
source = "registry+https://github.com/rust-lang/crates.io-index"
29483009
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
29493010

3011+
[[package]]
3012+
name = "plist"
3013+
version = "1.6.1"
3014+
source = "registry+https://github.com/rust-lang/crates.io-index"
3015+
checksum = "d9d34169e64b3c7a80c8621a48adaf44e0cf62c78a9b25dd9dd35f1881a17cf9"
3016+
dependencies = [
3017+
"base64",
3018+
"indexmap",
3019+
"line-wrap",
3020+
"quick-xml",
3021+
"serde",
3022+
"time",
3023+
]
3024+
3025+
[[package]]
3026+
name = "polib"
3027+
version = "0.2.0"
3028+
source = "registry+https://github.com/rust-lang/crates.io-index"
3029+
checksum = "6b393b155cf9be86249cba1b56cc81be0e6212c66d94ac0d76d37a1761f3bb1b"
3030+
dependencies = [
3031+
"linereader",
3032+
]
3033+
29503034
[[package]]
29513035
name = "polonius-engine"
29523036
version = "0.13.0"
@@ -3062,12 +3146,30 @@ version = "0.10.0"
30623146
source = "registry+https://github.com/rust-lang/crates.io-index"
30633147
checksum = "d5d8f9aa0e3cbcfaf8bf00300004ee3b72f74770f9cbac93f6928771f613276b"
30643148

3149+
[[package]]
3150+
name = "pulldown-cmark-to-cmark"
3151+
version = "11.2.0"
3152+
source = "registry+https://github.com/rust-lang/crates.io-index"
3153+
checksum = "6dd464f32d7631035e849fcd969a603e9bb17ceaebe8467352a7728147f34e42"
3154+
dependencies = [
3155+
"pulldown-cmark 0.9.6",
3156+
]
3157+
30653158
[[package]]
30663159
name = "punycode"
30673160
version = "0.4.1"
30683161
source = "registry+https://github.com/rust-lang/crates.io-index"
30693162
checksum = "e9e1dcb320d6839f6edb64f7a4a59d39b30480d4d1765b56873f7c858538a5fe"
30703163

3164+
[[package]]
3165+
name = "quick-xml"
3166+
version = "0.31.0"
3167+
source = "registry+https://github.com/rust-lang/crates.io-index"
3168+
checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33"
3169+
dependencies = [
3170+
"memchr",
3171+
]
3172+
30713173
[[package]]
30723174
name = "quine-mc_cluskey"
30733175
version = "0.2.4"
@@ -3194,12 +3296,13 @@ dependencies = [
31943296

31953297
[[package]]
31963298
name = "regex"
3197-
version = "1.8.4"
3299+
version = "1.9.4"
31983300
source = "registry+https://github.com/rust-lang/crates.io-index"
3199-
checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f"
3301+
checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29"
32003302
dependencies = [
32013303
"aho-corasick",
32023304
"memchr",
3305+
"regex-automata 0.3.7",
32033306
"regex-syntax 0.7.5",
32043307
]
32053308

@@ -3223,9 +3326,14 @@ dependencies = [
32233326

32243327
[[package]]
32253328
name = "regex-automata"
3226-
version = "0.3.9"
3329+
version = "0.3.7"
32273330
source = "registry+https://github.com/rust-lang/crates.io-index"
3228-
checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9"
3331+
checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629"
3332+
dependencies = [
3333+
"aho-corasick",
3334+
"memchr",
3335+
"regex-syntax 0.7.5",
3336+
]
32293337

32303338
[[package]]
32313339
name = "regex-lite"
@@ -3340,6 +3448,7 @@ dependencies = [
33403448
"clap",
33413449
"env_logger",
33423450
"mdbook",
3451+
"mdbook-i18n-helpers",
33433452
]
33443453

33453454
[[package]]
@@ -5374,6 +5483,28 @@ dependencies = [
53745483
"syn 2.0.58",
53755484
]
53765485

5486+
[[package]]
5487+
name = "syntect"
5488+
version = "5.2.0"
5489+
source = "registry+https://github.com/rust-lang/crates.io-index"
5490+
checksum = "874dcfa363995604333cf947ae9f751ca3af4522c60886774c4963943b4746b1"
5491+
dependencies = [
5492+
"bincode",
5493+
"bitflags 1.3.2",
5494+
"flate2",
5495+
"fnv",
5496+
"once_cell",
5497+
"onig",
5498+
"plist",
5499+
"regex-syntax 0.8.3",
5500+
"serde",
5501+
"serde_derive",
5502+
"serde_json",
5503+
"thiserror",
5504+
"walkdir",
5505+
"yaml-rust",
5506+
]
5507+
53775508
[[package]]
53785509
name = "sysinfo"
53795510
version = "0.30.8"
@@ -5514,6 +5645,12 @@ dependencies = [
55145645
"std",
55155646
]
55165647

5648+
[[package]]
5649+
name = "textwrap"
5650+
version = "0.16.1"
5651+
source = "registry+https://github.com/rust-lang/crates.io-index"
5652+
checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9"
5653+
55175654
[[package]]
55185655
name = "thin-vec"
55195656
version = "0.2.13"
@@ -6527,6 +6664,15 @@ dependencies = [
65276664
"lzma-sys",
65286665
]
65296666

6667+
[[package]]
6668+
name = "yaml-rust"
6669+
version = "0.4.5"
6670+
source = "registry+https://github.com/rust-lang/crates.io-index"
6671+
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
6672+
dependencies = [
6673+
"linked-hash-map",
6674+
]
6675+
65306676
[[package]]
65316677
name = "yansi-term"
65326678
version = "0.1.2"

src/bootstrap/src/core/build_steps/doc.rs

+29-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ macro_rules! submodule_helper {
2929
}
3030

3131
macro_rules! book {
32-
($($name:ident, $path:expr, $book_name:expr $(, submodule $(= $submodule:literal)? )? ;)+) => {
32+
($($name:ident, $path:expr, $book_name:expr, $lang:expr $(, submodule $(= $submodule:literal)? )? ;)+) => {
3333
$(
3434
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
3535
pub struct $name {
@@ -61,6 +61,7 @@ macro_rules! book {
6161
name: $book_name.to_owned(),
6262
src: builder.src.join($path),
6363
parent: Some(self),
64+
languages: $lang.into(),
6465
})
6566
}
6667
}
@@ -74,15 +75,15 @@ macro_rules! book {
7475
// FIXME: Make checking for a submodule automatic somehow (maybe by having a list of all submodules
7576
// and checking against it?).
7677
book!(
77-
CargoBook, "src/tools/cargo/src/doc", "cargo", submodule = "src/tools/cargo";
78-
ClippyBook, "src/tools/clippy/book", "clippy";
79-
EditionGuide, "src/doc/edition-guide", "edition-guide", submodule;
80-
EmbeddedBook, "src/doc/embedded-book", "embedded-book", submodule;
81-
Nomicon, "src/doc/nomicon", "nomicon", submodule;
82-
Reference, "src/doc/reference", "reference", submodule;
83-
RustByExample, "src/doc/rust-by-example", "rust-by-example", submodule;
84-
RustdocBook, "src/doc/rustdoc", "rustdoc";
85-
StyleGuide, "src/doc/style-guide", "style-guide";
78+
CargoBook, "src/tools/cargo/src/doc", "cargo", &[], submodule = "src/tools/cargo";
79+
ClippyBook, "src/tools/clippy/book", "clippy", &[];
80+
EditionGuide, "src/doc/edition-guide", "edition-guide", &[], submodule;
81+
EmbeddedBook, "src/doc/embedded-book", "embedded-book", &[], submodule;
82+
Nomicon, "src/doc/nomicon", "nomicon", &[], submodule;
83+
Reference, "src/doc/reference", "reference", &[], submodule;
84+
RustByExample, "src/doc/rust-by-example", "rust-by-example", &["ja"], submodule;
85+
RustdocBook, "src/doc/rustdoc", "rustdoc", &[];
86+
StyleGuide, "src/doc/style-guide", "style-guide", &[];
8687
);
8788

8889
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -110,6 +111,7 @@ impl Step for UnstableBook {
110111
name: "unstable-book".to_owned(),
111112
src: builder.md_doc_out(self.target).join("unstable-book"),
112113
parent: Some(self),
114+
languages: vec![],
113115
})
114116
}
115117
}
@@ -120,6 +122,7 @@ struct RustbookSrc<P: Step> {
120122
name: String,
121123
src: PathBuf,
122124
parent: Option<P>,
125+
languages: Vec<&'static str>,
123126
}
124127

125128
impl<P: Step> Step for RustbookSrc<P> {
@@ -151,7 +154,19 @@ impl<P: Step> Step for RustbookSrc<P> {
151154
builder.info(&format!("Rustbook ({target}) - {name}"));
152155
let _ = fs::remove_dir_all(&out);
153156

154-
builder.run(rustbook_cmd.arg("build").arg(src).arg("-d").arg(out));
157+
builder.run(rustbook_cmd.arg("build").arg(&src).arg("-d").arg(&out));
158+
159+
for lang in &self.languages {
160+
let out = out.join(lang);
161+
162+
builder.info(&format!("Rustbook ({target}) - {name} - {lang}"));
163+
let _ = fs::remove_dir_all(&out);
164+
165+
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
166+
builder.run(
167+
rustbook_cmd.arg("build").arg(&src).arg("-d").arg(&out).arg("-l").arg(lang),
168+
);
169+
}
155170
}
156171

157172
if self.parent.is_some() {
@@ -214,6 +229,7 @@ impl Step for TheBook {
214229
name: "book".to_owned(),
215230
src: absolute_path.clone(),
216231
parent: Some(self),
232+
languages: vec![],
217233
});
218234

219235
// building older edition redirects
@@ -225,6 +241,7 @@ impl Step for TheBook {
225241
// There should only be one book that is marked as the parent for each target, so
226242
// treat the other editions as not having a parent.
227243
parent: Option::<Self>::None,
244+
languages: vec![],
228245
});
229246
}
230247

@@ -1200,6 +1217,7 @@ impl Step for RustcBook {
12001217
name: "rustc".to_owned(),
12011218
src: out_base,
12021219
parent: Some(self),
1220+
languages: vec![],
12031221
});
12041222
}
12051223
}

src/tools/rustbook/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ edition = "2021"
77
[dependencies]
88
clap = "4.0.32"
99
env_logger = "0.11"
10+
# Some modifications to mdbook-i18n-helpers are required for this PR.
11+
# So after checking this draft PR is acceptable, I'll send a PR to the original mdbook-i18n-helpers.
12+
# After the PR is merged and a new version is released, I'll change this entry.
13+
mdbook-i18n-helpers = {git = "https://github.com/dalance/mdbook-i18n-helpers", branch = "export_preprocessor"}
1014

1115
[dependencies.mdbook]
1216
version = "0.4.37"

0 commit comments

Comments
 (0)