build.rs 830 B

123456789101112131415161718192021222324252627282930313233
  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 schemars::schema_for;
  6. use tauri_utils::{
  7. acl::{capability::Capability, Permission, Scopes},
  8. write_if_changed,
  9. };
  10. macro_rules! schema {
  11. ($name:literal, $path:ty) => {
  12. (concat!($name, "-schema.json"), schema_for!($path))
  13. };
  14. }
  15. pub fn main() -> Result<(), Box<dyn Error>> {
  16. let schemas = [
  17. schema!("capability", Capability),
  18. schema!("permission", Permission),
  19. schema!("scope", Scopes),
  20. ];
  21. let out = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR")?);
  22. for (filename, schema) in schemas {
  23. let schema = serde_json::to_string_pretty(&schema)?;
  24. write_if_changed(out.join(filename), schema)?;
  25. }
  26. Ok(())
  27. }