File: build.rs

package info (click to toggle)
rust-wasmtime 26.0.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 48,492 kB
  • sloc: ansic: 4,003; sh: 561; javascript: 542; cpp: 254; asm: 175; ml: 96; makefile: 55
file content (39 lines) | stat: -rw-r--r-- 1,536 bytes parent folder | download
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
use std::env;
use wasmtime_versioned_export_macros::versioned_suffix;

fn main() {
    let mut build = cc::Build::new();
    let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
    let os = env::var("CARGO_CFG_TARGET_OS").unwrap();

    // NB: Technically `cfg(sanitize = "address")` is not stable and requires a
    // `#![feature]` but sort of abuse the fact that cfgs are "leaked" through
    // into Cargo ungated via `--print cfg`. Translate that to `cfg(asan)` for
    // us to write down in the code.
    println!("cargo:rustc-check-cfg=cfg(asan)");
    match env::var("CARGO_CFG_SANITIZE") {
        Ok(s) if s == "address" => {
            println!("cargo:rustc-cfg=asan");
        }
        _ => {}
    }

    if os == "windows" {
        println!("cargo:rerun-if-changed=src/windows.c");
        build.file("src/windows.c");
        build.define("VERSIONED_SUFFIX", Some(versioned_suffix!()));
    } else if arch == "s390x" {
        println!("cargo:rerun-if-changed=src/unix/s390x.S");
        build.file("src/unix/s390x.S");
        build.define("VERSIONED_SUFFIX", Some(versioned_suffix!()));
    } else {
        // assume that this is included via inline assembly in the crate itself,
        // and the crate will otherwise have a `compile_error!` for unsupported
        // platforms.
        println!("cargo:rerun-if-changed=build.rs");
        return;
    }
    build.define(&format!("CFG_TARGET_OS_{os}"), None);
    build.define(&format!("CFG_TARGET_ARCH_{arch}"), None);
    build.compile("wasmtime-fiber");
}