build.rs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2019 Parity Technologies (UK) Ltd.
  2. // This file is part of Substrate.
  3. // Substrate is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. // Substrate is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with Substrate. If not, see <http://www.gnu.org/licenses/>.
  13. use std::{env, process::Command, string::String};
  14. use wasm_builder_runner::{build_current_project_with_rustflags, WasmBuilderSource};
  15. fn main() {
  16. if !in_real_cargo_environment() {
  17. env::set_var("BUILD_DUMMY_WASM_BINARY", "1");
  18. println!("Building DUMMY Wasm binary");
  19. }
  20. build_current_project_with_rustflags(
  21. "wasm_binary.rs",
  22. WasmBuilderSource::Crates("1.0.8"),
  23. // This instructs LLD to export __heap_base as a global variable, which is used by the
  24. // external memory allocator.
  25. "-Clink-arg=--export=__heap_base",
  26. );
  27. }
  28. fn in_real_cargo_environment() -> bool {
  29. let cargo =
  30. env::var("CARGO").expect("`CARGO` env variable is always set when executing `build.rs`.");
  31. let mut cmd = Command::new(cargo);
  32. cmd.arg("--version");
  33. let output = cmd.output().expect("failed to get cargo version");
  34. let version = String::from_utf8(output.stdout).unwrap();
  35. println!("{}", version);
  36. // if we are building in an IDE (Code or Atom) with RLS extension the version
  37. // would start with "rls"
  38. version.starts_with("cargo")
  39. }