build.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2019-2024 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. use std::{error::Error, path::PathBuf};
  5. use tauri_utils::{
  6. acl::{capability::Capability, Permission, Scopes},
  7. config::Config,
  8. write_if_changed,
  9. };
  10. macro_rules! schema {
  11. ($name:literal, $path:ty) => {
  12. (concat!($name, ".schema.json"), schemars::schema_for!($path))
  13. };
  14. }
  15. pub fn main() -> Result<(), Box<dyn Error>> {
  16. let schemas = [
  17. schema!("config", Config),
  18. schema!("capability", Capability),
  19. schema!("permission", Permission),
  20. schema!("scope", Scopes),
  21. ];
  22. let out = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR")?);
  23. let schemas_dir = out.join("schemas");
  24. std::fs::create_dir_all(&schemas_dir)?;
  25. for (filename, schema) in schemas {
  26. let schema = serde_json::to_string_pretty(&schema)?;
  27. write_if_changed(schemas_dir.join(filename), &schema)?;
  28. if filename.starts_with("config") {
  29. write_if_changed(out.join("../tauri-cli/config.schema.json"), schema)?;
  30. }
  31. }
  32. Ok(())
  33. }