File: build.rs

package info (click to toggle)
rust-swc-core 35.0.0~ds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 62,816 kB
  • sloc: javascript: 873; xml: 538; sh: 358; makefile: 35; python: 5
file content (37 lines) | stat: -rw-r--r-- 1,252 bytes parent folder | download | duplicates (2)
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
use std::{
    env,
    fs::File,
    io::{BufWriter, Write},
    path::Path,
};

use vergen::EmitBuilder;

// Validate conflict between host / plugin features
#[cfg(all(
    feature = "ecma_plugin_transform",
    any(
        feature = "plugin_transform_host_native",
        feature = "plugin_transform_host_js"
    )
))]
compile_error!(
    "'plugin_transform' and 'plugin_transform_host*' features are mutually exclusive. If you're \
     writing a plugin, use 'plugin_transform' feature. If you're writing a custom SWC binary to \
     run plugin, use 'plugin_transform_host_*' instead."
);

fn main() {
    // Creates a static compile time constants for the version of swc_core.
    let pkg_version = env::var("CARGO_PKG_VERSION").unwrap();
    let out_dir = env::var("OUT_DIR").expect("Outdir should exist");
    let dest_path = Path::new(&out_dir).join("core_pkg_version.txt");
    let mut f = BufWriter::new(
        File::create(dest_path).expect("Failed to create swc_core version constant"),
    );
    write!(f, "{pkg_version}").expect("Failed to write swc_core version constant");

    // Attempt to collect some build time env values but will skip if there are any
    // errors.
    let _ = EmitBuilder::builder().all_cargo().emit();
}