Skip to content

Commit cee3426

Browse files
committed
deal with unicode website being down
1 parent 0be509c commit cee3426

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

compiler/build.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
use std::{env, fs, ops::Range, path::Path};
22

3-
fn main() -> Result<(), Box<dyn std::error::Error>> {
3+
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
4+
5+
fn main() -> Result<()> {
6+
if let Err(err) = generate() {
7+
if char::UNICODE_VERSION == (13, 0, 0) {
8+
// if unable to generate the script from data files (e.g. if the
9+
// unicode website is down ... ) get a pre generated version
10+
// from a github gist
11+
// This should not be needed ugh
12+
pre_generated()?;
13+
} else {
14+
return Err(err);
15+
}
16+
}
17+
18+
Ok(())
19+
}
20+
21+
fn generate() -> Result<()> {
422
let out_dir = env::var_os("OUT_DIR").unwrap();
523
let dest_path = Path::new(&out_dir).join("unicode.rs");
624

@@ -169,7 +187,7 @@ impl GeneralCategory {
169187
}
170188

171189
// retrieve and parse the unicodedata.txt file
172-
fn unicode_data() -> Result<Vec<(u32, GeneralCategory)>, Box<dyn std::error::Error>> {
190+
fn unicode_data() -> Result<Vec<(u32, GeneralCategory)>> {
173191
let unicode_version = format!(
174192
"{}.{}.{}",
175193
char::UNICODE_VERSION.0,
@@ -194,7 +212,7 @@ fn unicode_data() -> Result<Vec<(u32, GeneralCategory)>, Box<dyn std::error::Err
194212
}
195213

196214
/// retrieve and parse the unicode case fold data
197-
fn casefold_data() -> Result<Vec<(String, String, String)>, Box<dyn std::error::Error>> {
215+
fn casefold_data() -> Result<Vec<(String, String, String)>> {
198216
let unicode_version = format!(
199217
"{}.{}.{}",
200218
char::UNICODE_VERSION.0,
@@ -246,3 +264,15 @@ fn compress_data(input: &[u32]) -> Vec<Range<char>> {
246264

247265
output
248266
}
267+
268+
fn pre_generated() -> Result<()> {
269+
let out_dir = env::var_os("OUT_DIR").unwrap();
270+
let dest_path = Path::new(&out_dir).join("unicode.rs");
271+
272+
let pre_generated = reqwest::blocking::get("https://gist.githubusercontent.com/OrangeBacon/ff701218dc0d77bb45b949c0e4bf4776/raw/7d262049ba26aeca022685ca91396e33b0196534/unicode13.0.0.rs")?
273+
.text()?;
274+
275+
fs::write(&dest_path, pre_generated)?;
276+
277+
Ok(())
278+
}

0 commit comments

Comments
 (0)