diff --git a/CHANGELOG.md b/CHANGELOG.md index 637b76e1945..3707cf3e53d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,11 @@ - [#2026](https://github.com/wasmerio/wasmer/pull/2010) Expose trap code of a `RuntimeError`, if it's a `Trap`. ### Changed +- [#2042](https://github.com/wasmerio/wasmer/pull/2042) Parse more exotic environment variables in `wasmer run`. - [#2041](https://github.com/wasmerio/wasmer/pull/2041) Documentation diagrams now have a solid white background rather than a transparent background. ### Fixed +- [#2044](https://github.com/wasmerio/wasmer/pull/2044) Do not build C headers on docs.rs. ## 1.0.1 - 2021-01-12 diff --git a/lib/c-api/build.rs b/lib/c-api/build.rs index db1b0ae0858..7982deb76eb 100644 --- a/lib/c-api/build.rs +++ b/lib/c-api/build.rs @@ -1,3 +1,8 @@ +//! This build script aims at: +//! +//! * generating the C header files for the C API, +//! * setting `inline-c` up. + use cbindgen::{Builder, Language}; use std::{env, fs, path::PathBuf}; @@ -59,11 +64,22 @@ fn main() { let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); let out_dir = env::var("OUT_DIR").unwrap(); - build_wasm_c_api_headers(&crate_dir, &out_dir); - build_wasmer_headers(&crate_dir, &out_dir); + if building_c_api_headers() { + build_wasm_c_api_headers(&crate_dir, &out_dir); + build_wasmer_c_api_headers(&crate_dir, &out_dir); + } + build_inline_c_env_vars(); } +/// Check whether we should build the C API headers. +/// +/// For the moment, it's always enabled, unless if the `DOCS_RS` +/// environment variable is present. +fn building_c_api_headers() -> bool { + env::var("DOCS_RS").is_err() +} + /// Build the header files for the `wasm_c_api` API. fn build_wasm_c_api_headers(crate_dir: &str, out_dir: &str) { let mut crate_header_file = PathBuf::from(crate_dir); @@ -126,7 +142,7 @@ fn build_wasm_c_api_headers(crate_dir: &str, out_dir: &str) { } /// Build the header files for the `deprecated` API. -fn build_wasmer_headers(crate_dir: &str, out_dir: &str) { +fn build_wasmer_c_api_headers(crate_dir: &str, out_dir: &str) { let mut crate_header_file = PathBuf::from(crate_dir); crate_header_file.push("wasmer"); diff --git a/lib/cli/src/utils.rs b/lib/cli/src/utils.rs index dfc693e91c1..a032f26f40b 100644 --- a/lib/cli/src/utils.rs +++ b/lib/cli/src/utils.rs @@ -40,14 +40,53 @@ pub fn parse_mapdir(entry: &str) -> Result<(String, PathBuf)> { } } -/// Parses a mapdir from an env var +/// Parses an environment variable. pub fn parse_envvar(entry: &str) -> Result<(String, String)> { - if let [env_var, value] = entry.split('=').collect::>()[..] { - Ok((env_var.to_string(), value.to_string())) - } else { - bail!( - "Env vars must be of the form =. Found {}", + let entry = entry.trim(); + + match entry.find('=') { + None => bail!( + "Environment variable must be of the form `=`; found `{}`", + &entry + ), + + Some(0) => bail!( + "Environment variable is not well formed, the `name` is missing in `=`; got `{}`", + &entry + ), + + Some(position) if position == entry.len() - 1 => bail!( + "Environment variable is not well formed, the `value` is missing in `=`; got `{}`", &entry + ), + + Some(position) => Ok((entry[..position].into(), entry[position + 1..].into())), + } +} + +#[cfg(test)] +mod tests { + use super::parse_envvar; + + #[test] + fn test_parse_envvar() { + assert_eq!( + parse_envvar("A").unwrap_err().to_string(), + "Environment variable must be of the form `=`; found `A`" + ); + assert_eq!( + parse_envvar("=A").unwrap_err().to_string(), + "Environment variable is not well formed, the `name` is missing in `=`; got `=A`" + ); + assert_eq!( + parse_envvar("A=").unwrap_err().to_string(), + "Environment variable is not well formed, the `value` is missing in `=`; got `A=`" + ); + assert_eq!(parse_envvar("A=B").unwrap(), ("A".into(), "B".into())); + assert_eq!(parse_envvar(" A=B\t").unwrap(), ("A".into(), "B".into())); + assert_eq!( + parse_envvar("A=B=C=D").unwrap(), + ("A".into(), "B=C=D".into()) ); } }