build.rs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // SPDX-License-Identifier: Apache-2.0
  2. use std::process::Command;
  3. fn main() {
  4. #[cfg(feature = "llvm")]
  5. {
  6. Command::new("make")
  7. .args(["-C", "stdlib"])
  8. .output()
  9. .expect("Could not build stdlib");
  10. // compile our linker
  11. let cxxflags = Command::new("llvm-config")
  12. .args(["--cxxflags"])
  13. .output()
  14. .expect("could not execute llvm-config");
  15. let cxxflags = String::from_utf8(cxxflags.stdout).unwrap();
  16. let mut build = cc::Build::new();
  17. build.file("src/linker/linker.cpp").cpp(true);
  18. if !cfg!(target_os = "windows") {
  19. build.flag("-Wno-unused-parameter");
  20. }
  21. for flag in cxxflags.split_whitespace() {
  22. build.flag(flag);
  23. }
  24. build.compile("liblinker.a");
  25. // add the llvm linker
  26. let libdir = Command::new("llvm-config")
  27. .args(["--libdir"])
  28. .output()
  29. .unwrap();
  30. let libdir = String::from_utf8(libdir.stdout).unwrap();
  31. println!("cargo:libdir={libdir}");
  32. for lib in &["lldELF", "lldCommon", "lldWasm"] {
  33. println!("cargo:rustc-link-lib=static={lib}");
  34. }
  35. // And all the symbols we're not using, needed by Windows and debug builds
  36. println!("cargo:rustc-link-lib=static=lldMachO");
  37. }
  38. let output = Command::new("git")
  39. .args(["describe", "--tags", "--always"])
  40. .output()
  41. .unwrap();
  42. let solang_version = if output.stdout.is_empty() {
  43. format!("v{}", env!("CARGO_PKG_VERSION"))
  44. } else {
  45. String::from_utf8(output.stdout).unwrap()
  46. };
  47. println!("cargo:rustc-env=SOLANG_VERSION={solang_version}");
  48. // Make sure we have an 8MiB stack on Windows. Windows defaults to a 1MB
  49. // stack, which is not big enough for debug builds
  50. #[cfg(windows)]
  51. println!("cargo:rustc-link-arg=/STACK:8388608");
  52. }