Skip to content

Commit 52c00d6

Browse files
authored
Add custom platform configuration (#65)
1 parent 04dcf7f commit 52c00d6

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ keywords = ["api-bindings", "wasm", "webassembly"]
3232
wamr-sys = { path = "crates/wamr-sys", version = "1.0.0" }
3333

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

3737
[[package.metadata.esp-idf-sys.extra_components]]
3838
bindings_header = "./crates/wamr-sys/wasm-micro-runtime/core/iwasm/include/wasm_export.h"
@@ -44,3 +44,4 @@ dump-call-stack = ["wamr-sys/dump-call-stack"]
4444
llvmjit = ["wamr-sys/llvmjit"]
4545
multi-module = ["wamr-sys/multi-module"]
4646
name-section = ["wamr-sys/name-section"]
47+
esp-idf = ["esp-idf-sys", "wamr-sys/esp-idf"]

crates/wamr-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ llvmjit = []
3737
multi-module = []
3838
name-section = [ "custom-section" ]
3939
std = []
40+
esp-idf = []

crates/wamr-sys/build.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,21 @@ fn main() {
1414
let wamr_root = wamr_root.join("wasm-micro-runtime");
1515
assert!(wamr_root.exists());
1616

17-
let no_espidf = env::var("CARGO_CFG_TARGET_OS").unwrap() != "espidf";
17+
println!("cargo:rerun-if-env-changed=WAMR_BUILD_PLATFORM");
18+
println!("cargo:rerun-if-env-changed=WAMR_SHARED_PLATFORM_CONFIG");
19+
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_ESP_IDF");
20+
21+
let is_espidf = env::var("CARGO_FEATURE_ESP_IDF").is_ok()
22+
&& env::var("CARGO_CFG_TARGET_OS").unwrap() == "espidf";
23+
24+
if is_espidf
25+
&& (env::var("WAMR_BUILD_PLATFORM").is_ok()
26+
|| env::var("WAMR_SHARED_PLATFORM_CONFIG").is_ok())
27+
{
28+
panic!("ESP-IDF build cannot use custom platform build (WAMR_BUILD_PLATFORM) or shared platform config (WAMR_SHARED_PLATFORM_CONFIG)");
29+
}
1830
// because the ESP-IDF build procedure differs from the regular one (build internally by esp-idf-sys),
19-
if no_espidf {
31+
else {
2032
let enable_custom_section = if cfg!(feature = "custom-section") {
2133
"1"
2234
} else {
@@ -63,6 +75,15 @@ fn main() {
6375
.define("WAMR_BUILD_CUSTOM_NAME_SECTION", enable_name_section)
6476
.define("WAMR_BUILD_LOAD_CUSTOM_SECTION", enable_custom_section);
6577

78+
if let Ok(platform_name) = env::var("WAMR_BUILD_PLATFORM") {
79+
cfg.define("WAMR_BUILD_PLATFORM", &platform_name);
80+
}
81+
82+
if let Ok(platform_config) = env::var("WAMR_SHARED_PLATFORM_CONFIG") {
83+
cfg.define("SHARED_PLATFORM_CONFIG", &platform_config);
84+
println!("cargo:rerun-if-changed={}", platform_config);
85+
}
86+
6687
// support STDIN/STDOUT/STDERR redirect.
6788
cfg = match env::var("WAMR_BH_VPRINTF") {
6889
Ok(bh_vprintf) => match bh_vprintf.len() {

0 commit comments

Comments
 (0)