Skip to content

Commit

Permalink
Remove WASM providers
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejressel committed Dec 24, 2024
1 parent 1b559c6 commit 8ed799f
Show file tree
Hide file tree
Showing 67 changed files with 268 additions and 2,453 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ jobs:
pulumi_wasm_generator_lib/tests/output/nested-module/
pulumi_wasm_generator_lib/tests/output/nested-module-thirdparty/
# DO NOT EDIT - END 1
- name: Regenerate provider list
run: just regenerate-provider-list
- name: Regenerator
run: just regenerator
- name: Check
run: just check
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions examples/typesystem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ mod tests {
}

fn resource_compilation_test() {
let _ = pulumi_wasm_providers_typesystem::deep::nested::module::some_resource::create(
pulumi_wasm_providers_typesystem::deep::nested::module::some_resource::create(
"test",
SomeResourceArgs::builder().build_struct(),
);
}

fn function_compilation_test() {
let _ = pulumi_wasm_providers_typesystem::functions::deep::nested::module::some_function::invoke();
pulumi_wasm_providers_typesystem::functions::deep::nested::module::some_function::invoke();
}

fn types_compilation_test() {
Expand Down
79 changes: 1 addition & 78 deletions pulumi_wasm_generator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};
use tempfile;

use pulumi_wasm_generator_lib::{
extract_micro_package, generate_combined, generate_rust_library, generate_wasm_provider,
};
use pulumi_wasm_generator_lib::{extract_micro_package, generate_combined};
use std::path::Path;
use std::{env, fs};

Expand Down Expand Up @@ -72,76 +68,3 @@ pub fn generate_from_schema(schema_file: &Path) {
generate_combined(schema_file, &location).unwrap();
println!("cargo::rerun-if-changed=build.rs");
}

fn main() -> Result<()> {
let args = App::parse();

match args.command {
Command::GenProvider {
schema,
output: destination,
remove,
} => {
check_if_schema_exists(schema.as_ref())?;
check_if_not_empty(destination.as_ref(), remove)?;
generate_wasm_provider(schema.as_ref(), destination.as_ref())?;
}
Command::GenRust {
schema,
output: destination,
remove,
} => {
check_if_schema_exists(schema.as_ref())?;
check_if_not_empty(destination.as_ref(), remove)?;
generate_rust_library(schema.as_ref(), destination.as_ref())?;
}
};

Ok(())
}

fn check_if_schema_exists(schema: &Path) -> Result<()> {
if !schema.exists() {
Err(anyhow::anyhow!(
"Schema file [{}] does not exist",
schema.display()
))
} else if !schema.is_file() {
Err(anyhow::anyhow!(
"Schema [{}] is not a file",
schema.display()
))
} else {
Ok(())
}
}

fn check_if_not_empty(output_directory: &Path, remove: Option<bool>) -> Result<()> {
let remove = remove.unwrap_or(false);
if output_directory.exists() && remove {
fs::remove_dir_all(output_directory).context(format!(
"Cannot remove directory [{}]",
output_directory.display()
))?;
}
fs::create_dir_all(output_directory).context(format!(
"Cannot create directory [{}]",
output_directory.display()
))?;
let is_empty = output_directory
.read_dir()
.context(format!(
"Cannot read directory [{}]",
output_directory.display()
))?
.next()
.is_none();
if !is_empty {
Err(anyhow::anyhow!(
"Directory \"{}\" is not empty",
output_directory.display()
))
} else {
Ok(())
}
}
95 changes: 4 additions & 91 deletions pulumi_wasm_generator_lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,111 +1,24 @@
use crate::schema::Package;
use anyhow::{Context, Result};
use std::fs;
use std::fs::File;
use std::io::{BufReader, Write};
use std::io::BufReader;
use std::path::Path;

use crate::output::rust::functions::generate_function_code;
use crate::output::rust::resources::generate_resources_code;
use crate::schema::Package;
use anyhow::{Context, Result};
use output::rust::types::generate_types_code;

mod code_generation;
mod description;
mod model;
mod output;
mod schema;
mod utils;

pub fn generate_rust_library(schema_json: &Path, result_path: &Path) -> Result<()> {
let schema_package: schema::Package = extract_schema_from_file(schema_json)?;
let package = schema::to_model(&schema_package)?;

fs::create_dir_all(result_path.join("wit").join("deps"))?;
fs::create_dir_all(result_path.join("src"))?;
fs::create_dir_all(result_path.join("src").join("resource"))?;
fs::create_dir_all(result_path.join("src").join("types"))?;
fs::create_dir_all(result_path.join("src").join("function"))?;

let mut wit_file = File::create(result_path.join("wit").join("world.wit"))?;
wit_file.write_all(output::wit::generate_wit(&package)?.as_ref())?;

let mut deps_wit_file =
File::create(result_path.join("wit").join("deps").join("pulumi-wasm.wit"))?;
deps_wit_file.write_all(output::wit::get_dependencies()?.as_ref())?;

let mut cargo_file = File::create(result_path.join("Cargo.toml"))?;
cargo_file.write_all(output::rust::cargo::generate_cargo(&package).as_bytes())?;

let mut lib_file = File::create(result_path.join("src").join("lib.rs"))?;
lib_file
.write_all(output::rust::source_code_librs::generate_source_code(&package).as_bytes())?;

generate_types_code(&package, result_path);
generate_resources_code(&package, result_path);
generate_function_code(&package, result_path);

Ok(())
}

pub fn generate_wasm_provider(schema_json: &Path, result_path: &Path) -> Result<()> {
let schema_package: schema::Package = extract_schema_from_file(schema_json)?;
let package = schema::to_model(&schema_package)?;

fs::create_dir_all(result_path.join("wit").join("deps"))?;
fs::create_dir_all(result_path.join("src").join("resource"))?;
fs::create_dir_all(result_path.join("src").join("function"))?;

let mut wit_file = File::create(result_path.join("wit").join("world.wit"))?;
wit_file.write_all(output::wit::generate_wit(&package)?.as_ref())?;

let mut deps_wit_file =
File::create(result_path.join("wit").join("deps").join("pulumi-wasm.wit"))?;
deps_wit_file.write_all(output::wit::get_dependencies()?.as_ref())?;

let mut cargo_file = File::create(result_path.join("Cargo.toml"))?;
cargo_file.write_all(output::provider::cargo::generate_cargo(&package).as_bytes())?;

let mut lib_file = File::create(result_path.join("src").join("lib.rs"))?;
lib_file.write_all(
output::provider::source_code_librs::generate_source_code(&package).as_bytes(),
)?;

let mut source_file = File::create(result_path.join("src").join("resource").join("mod.rs"))?;
source_file.write_all(
output::provider::source_code_resource_mod::generate_source_code(&package).as_bytes(),
)?;

output::provider::source_code_resource_code::generate_source_code(&package)
.iter()
.for_each(|(path, content)| {
let mut lib_file =
File::create(result_path.join("src").join("resource").join(path)).unwrap();
lib_file.write_all(content.as_bytes()).unwrap();
});

let mut source_file = File::create(result_path.join("src").join("function").join("mod.rs"))?;
source_file.write_all(
output::provider::source_code_function_mod::generate_source_code(&package).as_bytes(),
)?;

output::provider::source_code_function_code::generate_source_code(&package)
.iter()
.for_each(|(path, content)| {
let mut lib_file =
File::create(result_path.join("src").join("function").join(path)).unwrap();
lib_file.write_all(content.as_bytes()).unwrap();
});

Ok(())
}

pub fn generate_combined(schema_json: &Path, result_path: &Path) -> Result<()> {
let schema_package: schema::Package = extract_schema_from_file(schema_json)?;
let package = schema::to_model(&schema_package)?;

fs::create_dir_all(result_path)?;

output::combined::generate_combined_code(&package, result_path);
output::generate_combined_code(&package, result_path);

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::output::get_main_version;
use crate::utils::get_main_version;
use handlebars::Handlebars;
use serde::Serialize;
use serde_json::json;
Expand Down
Loading

0 comments on commit 8ed799f

Please sign in to comment.