From 538911ea494dc2e7aa3dfb5674b3751505c62dd7 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 24 Dec 2023 17:47:25 +0100 Subject: [PATCH] Improve the version parser of Emscripten Some Emscripten versions come with `-git` attached, so trim any non-numeric chars from the end of the string. See: /~https://github.com/rust-lang/rust/issues/119250. --- build.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index ee99981881c04..7174e01bf75e1 100644 --- a/build.rs +++ b/build.rs @@ -274,7 +274,12 @@ fn emcc_version_code() -> Option { return None; } let version = stdout.unwrap(); - let mut pieces = version.trim().split('.'); + + // Some Emscripten versions come with `-git` attached, so trim any + // non-numeric chars from the end of the string. + let mut pieces = version + .trim_end_matches(|c: char| !c.is_ascii_digit()) + .split('.'); let major = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0); let minor = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0);