build.rs 1.9 KB

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