Skip to content

Commit

Permalink
Add custom platform configuration (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlixANNERAUD authored Sep 10, 2024
1 parent 04dcf7f commit 52c00d6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ keywords = ["api-bindings", "wasm", "webassembly"]
wamr-sys = { path = "crates/wamr-sys", version = "1.0.0" }

[target.'cfg( target_os = "espidf" )'.dependencies]
esp-idf-sys = { version = "0.35" }
esp-idf-sys = { version = "0.35", optional = true }

[[package.metadata.esp-idf-sys.extra_components]]
bindings_header = "./crates/wamr-sys/wasm-micro-runtime/core/iwasm/include/wasm_export.h"
Expand All @@ -44,3 +44,4 @@ dump-call-stack = ["wamr-sys/dump-call-stack"]
llvmjit = ["wamr-sys/llvmjit"]
multi-module = ["wamr-sys/multi-module"]
name-section = ["wamr-sys/name-section"]
esp-idf = ["esp-idf-sys", "wamr-sys/esp-idf"]
1 change: 1 addition & 0 deletions crates/wamr-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ llvmjit = []
multi-module = []
name-section = [ "custom-section" ]
std = []
esp-idf = []
25 changes: 23 additions & 2 deletions crates/wamr-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,21 @@ fn main() {
let wamr_root = wamr_root.join("wasm-micro-runtime");
assert!(wamr_root.exists());

let no_espidf = env::var("CARGO_CFG_TARGET_OS").unwrap() != "espidf";
println!("cargo:rerun-if-env-changed=WAMR_BUILD_PLATFORM");
println!("cargo:rerun-if-env-changed=WAMR_SHARED_PLATFORM_CONFIG");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_ESP_IDF");

let is_espidf = env::var("CARGO_FEATURE_ESP_IDF").is_ok()
&& env::var("CARGO_CFG_TARGET_OS").unwrap() == "espidf";

if is_espidf
&& (env::var("WAMR_BUILD_PLATFORM").is_ok()
|| env::var("WAMR_SHARED_PLATFORM_CONFIG").is_ok())
{
panic!("ESP-IDF build cannot use custom platform build (WAMR_BUILD_PLATFORM) or shared platform config (WAMR_SHARED_PLATFORM_CONFIG)");
}
// because the ESP-IDF build procedure differs from the regular one (build internally by esp-idf-sys),
if no_espidf {
else {
let enable_custom_section = if cfg!(feature = "custom-section") {
"1"
} else {
Expand Down Expand Up @@ -63,6 +75,15 @@ fn main() {
.define("WAMR_BUILD_CUSTOM_NAME_SECTION", enable_name_section)
.define("WAMR_BUILD_LOAD_CUSTOM_SECTION", enable_custom_section);

if let Ok(platform_name) = env::var("WAMR_BUILD_PLATFORM") {
cfg.define("WAMR_BUILD_PLATFORM", &platform_name);
}

if let Ok(platform_config) = env::var("WAMR_SHARED_PLATFORM_CONFIG") {
cfg.define("SHARED_PLATFORM_CONFIG", &platform_config);
println!("cargo:rerun-if-changed={}", platform_config);
}

// support STDIN/STDOUT/STDERR redirect.
cfg = match env::var("WAMR_BH_VPRINTF") {
Ok(bh_vprintf) => match bh_vprintf.len() {
Expand Down

0 comments on commit 52c00d6

Please sign in to comment.