content: [env]
  CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
  
  [tasks.verify]
  description = "Run most verification tasks"
  workspace = false
  dependencies = [
      "run-tests",
      "lint",
      "docs",
      "spell-check",
      "verify-doc-tests",
      "verify-formatting",
      "deny",
  ]
  
  [tasks.verify-all]
  description = "Run all verification tasks"
  workspace = false
  dependencies = [
      "run-all-tests",
      "lint",
      "docs",
      "spell-check",
      "verify-doc-tests",
      "verify-formatting",
      "deny",
  ]
  
  [tasks.run-tests]
  description = "Run tests using nextest runner for better performance"
  command = "cargo"
  workspace = false
  args = ["nextest", "run", "--workspace", "--all-features"]
  install_crate = "cargo-nextest"
  
  [tasks.run-all-tests]
  description = "Run all tests including ignored ones"
  command = "cargo"
  workspace = false
  args = [
      "nextest",
      "run",
      "--workspace",
      "--all-features",
      "--run-ignored",
      "all",
  ]
  install_crate = "cargo-nextest"
  
  [tasks.deny]
  workspace = false
  command = "cargo"
  args = ["deny", "check", "bans", "licenses", "sources"]
  install_crate = "cargo-deny"
  
  [tasks.spell-check]
  workspace = false
  command = "typos"
  install_crate = "typos-cli"
  
  [tasks.verify-doc-tests]
  workspace = false
  command = "cargo"
  args = ["test", "--workspace", "--doc", "--all-features"]
  
  [tasks.verify-formatting]
  workspace = false
  command = "cargo"
  args = ["fmt", "--check", "--all"]
  
  [tasks.lint]
  description = "Run Clippy with warnings treated as errors"
  workspace = false
  command = "cargo"
  args = [
      "clippy",
      "--workspace",
      "--tests",
      "--benches",
      "--all-features",
      "--",
      "-D",
      "warnings",
  ]
  
  [tasks.docs]
  description = "Generate documentation with warnings treated as errors"
  workspace = false
  command = "cargo"
  env = { "RUSTDOCFLAGS" = "--deny warnings" }
  args = [
      "doc",
      "--workspace",
      "--no-deps",
      "--all-features",
      "--document-private-items",
  ]
  
  [tasks.get-wasm-cxxlib]
  script_runner = "@rust"
  workspace = false
  script = '''
  //! ```cargo
  //! [dependencies]
  //! ureq = "2"
  //! zip = "2"
  //! ```
  fn main() -> Result<(), Box<dyn std::error::Error>> {
      let target_dir = "target/wasm-libcxx";
  
      // Check if library already exists
      if std::path::Path::new(target_dir).exists() {
          return Ok(());
      }
  
      let url = "https://github.com/maximmaxim345/wasm32-unknown-unknown-libcxx/releases/latest/download/wasm32-unknown-unknown-libcxx.zip";
  
      std::fs::create_dir_all(target_dir)?;
  
      println!("Downloading libcxx...");
      let response = ureq::get(url).call()?;
      let mut content = Vec::new();
      response.into_reader().read_to_end(&mut content)?;
  
      println!("Extracting archive to {}...", target_dir);
      let reader = std::io::Cursor::new(content);
      let mut archive = zip::ZipArchive::new(reader)?;
      archive.extract(target_dir)?;
  
      println!("WASM library successfully installed in {}", target_dir);
      Ok(())
  }
  '''
  
  [tasks.ensure-wasm-target]
  script_runner = "@rust"
  workspace = false
  script = '''
  fn main() -> Result<(), Box<dyn std::error::Error>> {
      let installed_targets = String::from_utf8(
          std::process::Command::new("rustup")
              .args(["+nightly", "target", "list", "--installed"])
              .output()?
              .stdout,
      )?;
  
      if !installed_targets.contains("wasm32-unknown-unknown") {
          println!("Installing wasm32-unknown-unknown target for nightly...");
  
          let status = std::process::Command::new("rustup")
              .args(["+nightly", "target", "add", "wasm32-unknown-unknown"])
              .status()?;
  
          if !status.success() {
              return Err("Failed to install wasm32-unknown-unknown target".into());
          }
      }
  
      Ok(())
  }
  '''
  
  [tasks.setup-wasm]
  description = "Setup WASM build environment"
  workspace = false
  dependencies = ["ensure-wasm-target", "get-wasm-cxxlib"]
  
  [tasks.build-wasm-dev]
  description = "Build WASM target (development)"
  workspace = false
  dependencies = ["setup-wasm"]
  script_runner = "@shell"
  # This works on cmd, bash, zsh and sh
  script = '''
  WASM32_UNKNOWN_UNKNOWN_STDLIB_DIR="$(pwd)/target/wasm-libcxx/wasm32-unknown-unknown-libcxx" # shell2batch:
  . $WASM32_UNKNOWN_UNKNOWN_STDLIB_DIR/env.sh # shell2batch: call target\wasm-libcxx\wasm32-unknown-unknown-libcxx\env.bat
  cd crates/cadara
  rustup run nightly wasm-pack build --target web --no-typescript --dev
  '''
  install_crate = "wasm-pack"
  
  [tasks.build-wasm-debug]
  description = "Build WASM target (with debug info)"
  workspace = false
  dependencies = ["build-wasm-dev"]
  script_runner = "@shell"
  script = '''
  WASM32_UNKNOWN_UNKNOWN_STDLIB_DIR="$(pwd)/target/wasm-libcxx/wasm32-unknown-unknown-libcxx" # shell2batch:
  . $WASM32_UNKNOWN_UNKNOWN_STDLIB_DIR/env.sh # shell2batch: call target\wasm-libcxx\wasm32-unknown-unknown-libcxx\env.bat
  wasm-bindgen target/wasm32-unknown-unknown/debug/cadara_lib.wasm --out-dir crates/cadara/pkg --target web --keep-debug
  '''
  install_crate = "wasm-bindgen-cli"
  
  [tasks.build-wasm-release]
  description = "Build WASM target (release)"
  workspace = false
  dependencies = ["setup-wasm"]
  script_runner = "@shell"
  script = '''
  WASM32_UNKNOWN_UNKNOWN_STDLIB_DIR="$(pwd)/target/wasm-libcxx/wasm32-unknown-unknown-libcxx" # shell2batch:
  . $WASM32_UNKNOWN_UNKNOWN_STDLIB_DIR/env.sh # shell2batch: call target\wasm-libcxx\wasm32-unknown-unknown-libcxx\env.bat
  cd crates/cadara
  rustup run nightly wasm-pack build --target web --no-typescript
  '''
  install_crate = "wasm-pack"
  
  [tasks.serve]
  description = "Serve the WASM application"
  workspace = false
  install_crate = "simple-http-server"
  command = "simple-http-server"
  args = ["--nocache", "-i", "-p", "8080", "-c=wasm,js", "crates/cadara"]
  
  [tasks.dev]
  description = "Serve development build"
  workspace = false
  dependencies = ["build-wasm-dev", "serve"]
  
  [tasks.debug]
  description = "Serve debug build"
  workspace = false
  dependencies = ["build-wasm-debug", "serve"]
  
  [tasks.release]
  description = "Serve release build"
  workspace = false
  dependencies = ["build-wasm-release", "serve"]
  
  [tasks.test-wasm]
  description = "Run tests on WASM build"
  workspace = false
  dependencies = ["setup-wasm"]
  script_runner = "@shell"
  script = '''
  WASM32_UNKNOWN_UNKNOWN_STDLIB_DIR="$(pwd)/target/wasm-libcxx/wasm32-unknown-unknown-libcxx" # shell2batch:
  . $WASM32_UNKNOWN_UNKNOWN_STDLIB_DIR/env.sh # shell2batch: call target\wasm-libcxx\wasm32-unknown-unknown-libcxx\env.bat
  cd crates/occara
  rustup run nightly wasm-pack test --node
  '''
  install_crate = "wasm-pack"
  
  [tasks.help]
  description = "Display help information about available tasks"
  workspace = false
  script_runner = "@rust"
  script = '''
  //! ```cargo
  //! [dependencies]
  //! colored = "2.0"
  //! ```
  use colored::*;
  
  fn main() {
      println!("{}", "CADara Build System".bold().blue());
      println!("\n{}", "Usage:".bold());
      println!("  cargo make <task-name>\n");
      println!("  cargo make verify         # Run verification suite");
      println!("  cargo make dev            # Start WASM development server");
      println!("  cargo make test-wasm      # Run WASM test suite");
  
      println!("\n{}", "Note:".bold());
      println!("  All commands must be executed from the repository root directory\n");
  
      println!("{}", "Primary Commands:".bold().green());
      println!("  verify      - Run standard verification suite");
      println!("  verify-all  - Run extended verification suite (including ignored tests)");
      println!("  dev         - Start WASM server");
      println!("  debug       - Start WASM server with debug symbols");
      println!("  release     - Start WASM production server\n");
  
      println!("{}", "Verification Tasks:".bold().yellow());
      println!("  run-tests         - Run workspace tests (via nextest)");
      println!("  run-all-tests     - Run all tests including ignored ones");
      println!("  lint              - Run Clippy");
      println!("  docs              - Generate documentation");
      println!("  spell-check       - Check for typos in codebase");
      println!("  verify-doc-tests  - Verify documentation examples");
      println!("  verify-formatting - Check code formatting");
      println!("  deny              - Check dependencies compliance\n");
  
      println!("{}", "WASM Operations:".bold().magenta());
      println!("  build-wasm-dev     - Build WASM target (development)");
      println!("  build-wasm-debug   - Build WASM target (with debug info)");
      println!("  build-wasm-release - Build WASM target (production)");
      println!("  test-wasm          - Run WASM-specific tests");
      println!("  serve              - Start local web server (port 8080)\n");
  }
  '''
  