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 25, 2024
1 parent 8753149 commit 5ad420b
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 247 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ build-all-wasm-projects-release:
cargo component build -p pulumi_wasm_example_dependencies --release
cargo component build -p pulumi_wasm_example_multiple_providers --release

build-wasm-components-release:

check:
cargo fmt {{FORMATTABLE_PROJECTS}} -- --check

Expand Down
5 changes: 3 additions & 2 deletions providers/cloudflare/build.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions providers/docker/build.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions providers/random/build.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions providers/typesystem/build.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pulumi_wasm_generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap.workspace = true
pulumi_wasm_generator_lib.workspace = true
anyhow.workspace = true
tempfile = "3.14.0"
67 changes: 22 additions & 45 deletions pulumi_wasm_generator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,70 +1,47 @@
use clap::{Parser, Subcommand};

use anyhow::{Context, Result};
use pulumi_wasm_generator_lib::{extract_micro_package, generate_combined};
use std::path::Path;
use std::{env, fs};

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct App {
#[clap(subcommand)]
command: Command,
}

#[derive(Debug, Subcommand)]
enum Command {
GenProvider {
#[arg(short, long)]
schema: String,

#[arg(short, long)]
output: String,

#[arg(short, long)]
remove: Option<bool>,
},
GenRust {
#[arg(short, long)]
schema: String,

#[arg(short, long)]
output: String,

#[arg(short, long)]
remove: Option<bool>,
},
}

pub fn generate(provider_name: &str, provider_version: &str) {
pub fn generate(provider_name: &str, provider_version: &str) -> Result<()> {
let schema_output = std::process::Command::new("pulumi")
.arg("package")
.arg("get-schema")
.arg(format!("{}@{}", provider_name, provider_version))
.output()
.expect("Failed to execute pulumi command");
.context("Failed to execute pulumi command")?;

let schema = String::from_utf8(schema_output.stdout).expect("Invalid UTF-8 in pulumi output");

let out_dir = env::var_os("OUT_DIR").unwrap();
let out_dir = out_dir.to_str().unwrap();
let out_dir = env::var_os("OUT_DIR").context("Failed to get OUT_DIR environment variable")?;
let out_dir = out_dir
.to_str()
.context(format!("Failed to convert [{:?}] to string", out_dir))?;

let location = Path::new(out_dir).join("pulumi").join(provider_name);

let temp_dir = tempfile::tempdir().unwrap();
let temp_dir = tempfile::tempdir().context("Failed to create temporary directory")?;
let file = temp_dir.path().join("schema.json");
fs::write(&file, &schema).unwrap();
fs::write(&file, &schema).context("Failed to write schema")?;

generate_combined(file.as_path(), &location).unwrap();
generate_combined(file.as_path(), &location).context("Failed to generate glue files")?;
println!("cargo::rerun-if-changed=build.rs");

Ok(())
}

pub fn generate_from_schema(schema_file: &Path) {
let package = extract_micro_package(schema_file).unwrap();
pub fn generate_from_schema(schema_file: &Path) -> Result<()> {
let package = extract_micro_package(schema_file).context("Failed to deserialize package")?;
let provider_name = package.name;

let out_dir = env::var_os("OUT_DIR").unwrap();
let out_dir = out_dir.to_str().unwrap();
let out_dir = env::var_os("OUT_DIR").context("Failed to get OUT_DIR environment variable")?;
let out_dir = out_dir
.to_str()
.context(format!("Failed to convert [{:?}] to string", out_dir))?;
let location = Path::new(out_dir).join("pulumi").join(provider_name);

generate_combined(schema_file, &location).unwrap();
generate_combined(schema_file, &location).context("Failed to generate glue files")?;
println!("cargo::rerun-if-changed=build.rs");
println!("cargo::rerun-if-changed={}", schema_file.display());
Ok(())
}
88 changes: 0 additions & 88 deletions pulumi_wasm_generator_lib/src/output/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ use crate::model::{ElementId, Package};
use crate::output::functions::source_code_function_code::{
generate_docs, generate_single_function_source_code,
};
use crate::output::TreeNode;
use crate::utils::reformat_code;
use anyhow::Context;
use convert_case::{Case, Casing};
use std::fs::File;
use std::io::Write;

mod source_code_function_code;

Expand All @@ -20,87 +16,3 @@ pub(crate) fn generate_single_file(package: &Package, element_id: &ElementId) ->
pub(crate) fn generate_single_file_docs(package: &Package, element_id: &ElementId) -> Vec<String> {
generate_docs(package, element_id)
}

pub(crate) fn generate_function_code(package: &Package, result_path: &std::path::Path) {
if package.functions.is_empty() {
return;
}
let mut tree = TreeNode::new();

for element_id in package.functions.keys() {
tree.insert(element_id.clone());
}

generate_files(package, &tree, result_path);
}

fn generate_files(package: &Package, tree_node: &TreeNode, current_path: &std::path::Path) {
match tree_node {
TreeNode::Namespace(ns, functions) => {
std::fs::create_dir_all(current_path).unwrap();
for (name, node) in ns {
generate_files(package, node, &current_path.join(name));
}

for function in functions {
let file_name = format!(
"{}.rs",
function.get_rust_struct_name().to_case(Case::Snake)
);
let content = generate_single_function_source_code(package, function);
let mut file = File::create(current_path.join(file_name)).unwrap();
file.write_all(content.as_bytes()).unwrap();
}
}
}
}

pub(crate) fn generate_module_imports(package: &Package) -> String {
if package.functions.is_empty() {
return "".to_string();
}
let mut tree = TreeNode::new();

for element_id in package.functions.keys() {
tree.insert(element_id.clone());
}

generate_module_imports_1(package, &tree, std::path::Path::new("functions"))
}

fn generate_module_imports_1(
package: &Package,
tree_node: &TreeNode,
current_path: &std::path::Path,
) -> String {
match tree_node {
TreeNode::Namespace(ns, functions) => {
let mut s = String::new();

for (name, node) in ns {
s.push_str(&format!("pub mod {}{{\n", name));
s.push_str(&generate_module_imports_1(
package,
node,
&current_path.join(name),
));
s.push_str("}\n");
}

for function in functions {
s.push_str(&format!(
"pub mod {}{{\n",
function.get_rust_struct_name().to_case(Case::Snake)
));
s.push_str(&format!(
"include!(\"{}/{}.rs\");\n",
current_path.to_str().unwrap().replace("\\", "/"),
function.get_rust_struct_name().to_case(Case::Snake)
));
s.push_str("}\n");
}

s
}
}
}
5 changes: 1 addition & 4 deletions pulumi_wasm_generator_lib/src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ impl TreeNode {
}
}

pub(crate) fn generate_combined_code(
package: &crate::model::Package,
result_path: &std::path::Path,
) {
pub(crate) fn generate_combined_code(package: &Package, result_path: &std::path::Path) {
generate_files(
package,
&result_path.join("functions"),
Expand Down
97 changes: 0 additions & 97 deletions pulumi_wasm_generator_lib/src/output/resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ use crate::model::{ElementId, Package};
use crate::output::resources::source_code_resource_code::{
generate_docs, generate_single_resource_source_code,
};
use crate::output::TreeNode;
use crate::utils::reformat_code;
use anyhow::Context;
use convert_case::{Case, Casing};
use std::fs::File;
use std::io::Write;

pub(crate) fn generate_single_file(package: &Package, element_id: &ElementId) -> String {
reformat_code(&generate_single_resource_source_code(package, element_id))
Expand All @@ -20,96 +16,3 @@ pub(crate) fn generate_single_file(package: &Package, element_id: &ElementId) ->
pub(crate) fn generate_single_file_docs(package: &Package, element_id: &ElementId) -> Vec<String> {
generate_docs(package, element_id)
}

pub(crate) fn generate_resources_code(
package: &crate::model::Package,
result_path: &std::path::Path,
) {
if package.resources.is_empty() {
return;
}
let mut tree = TreeNode::new();

for element_id in package.resources.keys() {
tree.insert(element_id.clone());
}

println!("Tree {:?}", tree);

generate_files(package, &tree, result_path);
}

fn generate_files(
package: &crate::model::Package,
tree_node: &TreeNode,
current_path: &std::path::Path,
) {
match tree_node {
TreeNode::Namespace(ns, resources) => {
std::fs::create_dir_all(current_path).unwrap();
for (name, node) in ns {
generate_files(package, node, &current_path.join(name));
}

for resource in resources {
let file_name = format!(
"{}.rs",
resource.get_rust_struct_name().to_case(Case::Snake)
);
let content = generate_single_resource_source_code(package, resource);
let mut file = File::create(current_path.join(file_name)).unwrap();
file.write_all(content.as_bytes()).unwrap();
}
}
}
}

pub(crate) fn generate_module_imports(package: &Package) -> String {
if package.resources.is_empty() {
return "".to_string();
}
let mut tree = TreeNode::new();

for element_id in package.resources.keys() {
tree.insert(element_id.clone());
}

generate_module_imports_1(package, &tree, std::path::Path::new("resources"))
}

fn generate_module_imports_1(
package: &Package,
tree_node: &TreeNode,
current_path: &std::path::Path,
) -> String {
match tree_node {
TreeNode::Namespace(ns, functions) => {
let mut s = String::new();

for (name, node) in ns {
s.push_str(&format!("pub mod {}{{\n", name));
s.push_str(&generate_module_imports_1(
package,
node,
&current_path.join(name),
));
s.push_str("}\n");
}

for function in functions {
s.push_str(&format!(
"pub mod {}{{\n",
function.get_rust_struct_name().to_case(Case::Snake)
));
s.push_str(&format!(
"include!(\"{}/{}.rs\");\n",
current_path.to_str().unwrap().replace("\\", "/"),
function.get_rust_struct_name().to_case(Case::Snake)
));
s.push_str("}\n");
}

s
}
}
}
1 change: 0 additions & 1 deletion regenerator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::fs;
use std::process::Command;

#[derive(Debug)]
struct Provider<'a> {

Check warning

Code scanning / clippy

field version is never read Warning

field version is never read
Expand Down

0 comments on commit 5ad420b

Please sign in to comment.