build.rs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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::WasmBuilder;
  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. WasmBuilder::new()
  21. .with_current_project()
  22. .with_wasm_builder_from_crates("2.0.0")
  23. .export_heap_base()
  24. .import_memory()
  25. .build()
  26. }
  27. fn in_real_cargo_environment() -> bool {
  28. let cargo =
  29. env::var("CARGO").expect("`CARGO` env variable is always set when executing `build.rs`.");
  30. let mut cmd = Command::new(cargo);
  31. cmd.arg("--version");
  32. let output = cmd.output().expect("failed to get cargo version");
  33. let version = String::from_utf8(output.stdout).unwrap();
  34. println!("{}", version);
  35. // if we are building in an IDE (Code or Atom) with RLS extension the version
  36. // would start with "rls"
  37. version.starts_with("cargo")
  38. }