forked from matrix-org/matrix-rust-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
44 lines (40 loc) · 1.26 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::{env, process};
fn env_is_set(var_name: &str) -> bool {
env::var_os(var_name).is_some()
}
fn ensure(cond: bool, err: &str) {
if !cond {
eprintln!(
"\n\
┏━━━━━━━━{pad}━┓\n\
┃ error: {err} ┃\n\
┗━━━━━━━━{pad}━┛\n\
",
pad = "━".repeat(err.len()),
);
process::exit(1);
}
}
fn main() {
let native_tls_set = env_is_set("CARGO_FEATURE_NATIVE_TLS");
let rustls_tls_set = env_is_set("CARGO_FEATURE_RUSTLS_TLS");
ensure(
native_tls_set || rustls_tls_set,
"one of the features 'native-tls' or 'rustls-tls' must be enabled",
);
ensure(
!native_tls_set || !rustls_tls_set,
"only one of the features 'native-tls' or 'rustls-tls' can be enabled",
);
let is_wasm = env::var_os("CARGO_CFG_TARGET_ARCH").is_some_and(|arch| arch == "wasm32");
if is_wasm {
ensure(
!env_is_set("CARGO_FEATURE_SSO_LOGIN"),
"feature 'sso-login' is not available on target arch 'wasm32'",
);
ensure(
!env_is_set("CARGO_FEATURE_IMAGE_RAYON"),
"feature 'image-rayon' is not available on target arch 'wasm32'",
);
}
}