build.rs 2.0 KB

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