build.rs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. extern crate gcc;
  2. use std::env;
  3. use std::path::Path;
  4. use std::process::Command;
  5. struct Sources {
  6. files: Vec<&'static str>,
  7. }
  8. impl Sources {
  9. fn new() -> Sources {
  10. Sources { files: Vec::new() }
  11. }
  12. fn extend(&mut self, sources: &[&'static str]) {
  13. self.files.extend(sources);
  14. }
  15. }
  16. fn main() {
  17. if !Path::new("compiler-rt/.git").exists() {
  18. let _ = Command::new("git").args(&["submodule", "update", "--init"])
  19. .status();
  20. }
  21. let target = env::var("TARGET").expect("TARGET was not set");
  22. let cfg = &mut gcc::Config::new();
  23. if target.contains("msvc") {
  24. cfg.define("__func__", Some("__FUNCTION__"));
  25. } else {
  26. cfg.flag("-fno-builtin");
  27. cfg.flag("-fomit-frame-pointer");
  28. cfg.flag("-ffreestanding");
  29. }
  30. let mut sources = Sources::new();
  31. sources.extend(&[
  32. "muldi3.c",
  33. "mulosi4.c",
  34. "mulodi4.c",
  35. "divsi3.c",
  36. "divdi3.c",
  37. "modsi3.c",
  38. "moddi3.c",
  39. "divmodsi4.c",
  40. "divmoddi4.c",
  41. "ashldi3.c",
  42. "ashrdi3.c",
  43. "lshrdi3.c",
  44. "udivdi3.c",
  45. "umoddi3.c",
  46. "udivmoddi4.c",
  47. "udivsi3.c",
  48. "umodsi3.c",
  49. "udivmodsi4.c",
  50. "adddf3.c",
  51. "addsf3.c",
  52. "powidf2.c",
  53. "powisf2.c",
  54. "subdf3.c",
  55. "subsf3.c",
  56. "floatsisf.c",
  57. "floatsidf.c",
  58. "floatdidf.c",
  59. "floatunsisf.c",
  60. "floatunsidf.c",
  61. "floatundidf.c",
  62. // 128 bit integers
  63. "lshrti3.c",
  64. "modti3.c",
  65. "muloti4.c",
  66. "multi3.c",
  67. "udivmodti4.c",
  68. "udivti3.c",
  69. "umodti3.c",
  70. "ashlti3.c",
  71. "ashrti3.c",
  72. "divti3.c",
  73. ]);
  74. let builtins_dir = Path::new("compiler-rt/lib/builtins");
  75. for src in sources.files.iter() {
  76. cfg.file(builtins_dir.join(src));
  77. }
  78. cfg.compile("libcompiler-rt.a");
  79. println!("cargo:rerun-if-changed=build.rs");
  80. for source in sources.files.iter() {
  81. println!("cargo:rerun-if-changed={}", builtins_dir.join(source).display());
  82. }
  83. }