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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::env;
use std::io;
use std::path::Path;
use std::process::Command;
// Build script to compile the flowstdlib library (compile WASM files and generate manifest)
// using flowc
fn main() -> io::Result<()> {
let lib_root_dir_str = env!("CARGO_MANIFEST_DIR");
let lib_root_dir = Path::new(lib_root_dir_str);
let out_dir = if lib_root_dir.file_name().expect("Could not get file_name")
== env!("CARGO_PKG_NAME") {
// local build from source folder - always compile to same folder "target/flowstdlib"
let workspace_root_dir = lib_root_dir.parent()
.expect("Could not get parent directory");
let dir = workspace_root_dir.join("target/flowstdlib");
dir.to_string_lossy().to_string()
} else {
// package build from a copy of source with version number in folder name
env::var("OUT_DIR").expect("Could not get OUT_DIR")
};
// Tell Cargo that if any file changes it should rerun this build script
println!("cargo:rerun-if-changed={lib_root_dir_str}");
let mut command = Command::new("flowc");
// flowc options: -v info : to log output at INFO level,
// -n : only build native implementations and not compile WASM files
// -d : generate debug symbols in some output files (e.g. manifest.json)
// -g : dump 'dot' graphs for documentation
// -O : optimize the generated WASM output files
// -o : generate files in $out_dir instead of current working directory
// -n : do not compile to WASM, only compile a native version of the lib
// -l : compile a flow library (not a flow) who's path is the last arg
// If the "wasm" feature is activated, then don't set "-n" and flowc will compile
// implementations to wasm.
#[cfg(feature = "wasm")]
let command_args = vec!["-d", "-g", "-l", "-O", "-o", &out_dir, lib_root_dir_str];
// If the "wasm" feature is NOT activated, then set "-n" (native only) flag so flowc will
// not compile to wasm
#[cfg(not(feature = "wasm"))]
let command_args = vec!["-d", "-g", "-l", "-n", "-o", &out_dir, lib_root_dir_str];
match command.args(&command_args).status() {
Ok(stat) => {
if !stat.success() {
eprintln!("Error building sample, command line\n flowc {}",
command_args.join(" "));
std::process::exit(1);
}
}
Err(err) => {
eprintln!("'{}' running 'flowc {}'", err, command_args.join(" "));
std::process::exit(1);
}
}
Ok(())
}