blob: 1debd6b9c023eb2397aacbdeb8221a89e11e19a7 (
plain)
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
62
63
64
65
66
67
68
69
70
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
#[cfg(not(target_os = "windows"))]
fn build_tcc() {
use std::env;
{
// TODO(@littledivy): Windows support for fast call.
// let tcc_path = root
// .parent()
// .unwrap()
// .to_path_buf()
// .parent()
// .unwrap()
// .to_path_buf()
// .join("third_party")
// .join("prebuilt")
// .join("win");
// println!("cargo:rustc-link-search=native={}", tcc_path.display());
}
#[cfg(not(target_os = "windows"))]
{
use std::path::PathBuf;
use std::process::exit;
use std::process::Command;
let root = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR")));
let tcc_src = root.join("tinycc");
dbg!(&tcc_src);
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let mut configure = Command::new(tcc_src.join("configure"));
configure.current_dir(&out_dir);
configure.args(&["--enable-static", "--extra-cflags=-fPIC -O3 -g -static"]);
let status = configure.status().unwrap();
if !status.success() {
eprintln!("Fail to configure: {:?}", status);
exit(1);
}
let mut make = Command::new("make");
make.current_dir(&out_dir).arg(format!(
"-j{}",
env::var("NUM_JOBS").unwrap_or_else(|_| String::from("1"))
));
make.args(&["libtcc.a"]);
let status = make.status().unwrap();
if !status.success() {
eprintln!("Fail to make: {:?}", status);
exit(1);
}
println!("cargo:rustc-link-search=native={}", out_dir.display());
println!("cargo:rerun-if-changed={}", tcc_src.display());
}
}
#[cfg(target_os = "windows")]
fn main() {}
#[cfg(not(target_os = "windows"))]
fn main() {
use std::env;
if let Ok(tcc_path) = env::var("TCC_PATH") {
println!("cargo:rustc-link-search=native={}", tcc_path);
} else {
build_tcc();
}
println!("cargo:rustc-link-lib=static=tcc");
}
|