build.rs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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", "lldCommon", "lldWasm"] {
  29. println!("cargo:rustc-link-lib=static={}", lib);
  30. }
  31. // And all the symbols we're not using, needed by Windows and debug builds
  32. println!("cargo:rustc-link-lib=static=lldMachO");
  33. }
  34. let output = Command::new("git")
  35. .args(["describe", "--tags", "--always"])
  36. .output()
  37. .unwrap();
  38. let solang_version = if output.stdout.is_empty() {
  39. format!("v{}", env!("CARGO_PKG_VERSION"))
  40. } else {
  41. String::from_utf8(output.stdout).unwrap()
  42. };
  43. println!("cargo:rustc-env=SOLANG_VERSION={}", solang_version);
  44. // Make sure we have an 8MiB stack on Windows. Windows defaults to a 1MB
  45. // stack, which is not big enough for debug builds
  46. #[cfg(windows)]
  47. println!("cargo:rustc-link-arg=/STACK:8388608");
  48. }