Skip to content

Commit 4e1f500

Browse files
committed
In principle this looks promising if you ignore the acres of scar tissue
Signed-off-by: itowlson <[email protected]>
1 parent bd24bfe commit 4e1f500

File tree

7 files changed

+268
-170
lines changed

7 files changed

+268
-170
lines changed

src/commands/add.rs

Lines changed: 229 additions & 131 deletions
Large diffs are not rendered by default.

src/commands/gen.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
wit_bindgen::generate!({
2+
inline: r#"
3+
package imported:{!gen_name!};
4+
world imports {
5+
{!imps!}
6+
}
7+
"#,
8+
with: {
9+
{!gens!}
10+
},
11+
path: "{!dep_path!}",
12+
});

src/common/manifest.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use anyhow::{bail, Result};
1+
use anyhow::Result;
22
use spin_manifest::schema::v2::{AppManifest, ComponentDependencies, ComponentDependency};
3-
use std::path::PathBuf;
3+
use std::path::Path;
44
use tokio::fs;
55
use toml_edit::DocumentMut;
66

@@ -11,11 +11,11 @@ pub fn get_component_ids(manifest: &AppManifest) -> Vec<String> {
1111
// This is a helper function to edit the dependency table in the manifest file
1212
// while preserving the order of the manifest.
1313
pub async fn edit_component_deps_in_manifest(
14+
manifest_file: &Path,
1415
component_id: &str,
1516
component_deps: &ComponentDependencies,
1617
) -> Result<String> {
17-
let manifest_path = get_spin_manifest_path()?;
18-
let manifest = fs::read_to_string(manifest_path).await?;
18+
let manifest = fs::read_to_string(manifest_file).await?;
1919
let mut doc = manifest.parse::<DocumentMut>()?;
2020

2121
let mut dependencies_table = toml_edit::Table::new();
@@ -67,12 +67,3 @@ pub async fn edit_component_deps_in_manifest(
6767

6868
Ok(doc.to_string())
6969
}
70-
71-
// TODO: Eventually bring this function with the proposed Spin functionality of searching in parent Directories.
72-
pub fn get_spin_manifest_path() -> Result<PathBuf> {
73-
let manifest_path = PathBuf::from("spin.toml");
74-
if !manifest_path.exists() {
75-
bail!("No spin.toml file found in the current directory");
76-
}
77-
Ok(manifest_path)
78-
}

src/common/wit.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
use std::path::PathBuf;
2-
31
use anyhow::{Context, Result};
42
use wit_component::WitPrinter;
53
use wit_parser::{PackageId, Resolve};
64

7-
pub const DEFAULT_WIT: &str = r#"package spin-deps:[email protected];
8-
9-
world deps {
10-
}
11-
"#;
12-
135
/// Converts a Resolve object to WIT content.
146
pub fn resolve_to_wit(resolve: &Resolve, package_id: PackageId) -> Result<String> {
157
let mut printer = WitPrinter::default();
@@ -56,23 +48,23 @@ pub fn get_exported_interfaces(
5648
.collect()
5749
}
5850

59-
pub fn merge_dependecy_package(
60-
base_resolve_file: Option<&PathBuf>,
61-
dependency_resolve: &Resolve,
62-
dependency_pkg_id: PackageId,
63-
) -> Result<(Resolve, PackageId)> {
64-
let mut base_resolve = Resolve::default();
65-
let base_resolve_pkg_id = match base_resolve_file {
66-
Some(path) => base_resolve.push_file(path)?,
67-
None => base_resolve.push_str("base_resolve.wit", DEFAULT_WIT)?,
68-
};
69-
let base_resolve_world_id = base_resolve.select_world(base_resolve_pkg_id, Some("deps"))?;
51+
// pub fn merge_dependecy_package(
52+
// base_resolve_file: Option<&PathBuf>,
53+
// dependency_resolve: &Resolve,
54+
// dependency_pkg_id: PackageId,
55+
// ) -> Result<(Resolve, PackageId)> {
56+
// let mut base_resolve = Resolve::default();
57+
// let base_resolve_pkg_id = match base_resolve_file {
58+
// Some(path) => base_resolve.push_file(path)?,
59+
// None => base_resolve.push_str("base_resolve.wit", DEFAULT_WIT)?,
60+
// };
61+
// let base_resolve_world_id = base_resolve.select_world(base_resolve_pkg_id, Some("deps"))?;
7062

71-
let dependecy_main_world_id =
72-
dependency_resolve.select_world(dependency_pkg_id, Some("dependency-world"))?;
73-
let remap = base_resolve.merge(dependency_resolve.clone())?;
74-
let dependecy_world_id = remap.map_world(dependecy_main_world_id, None)?;
75-
base_resolve.merge_worlds(dependecy_world_id, base_resolve_world_id)?;
63+
// let dependecy_main_world_id =
64+
// dependency_resolve.select_world(dependency_pkg_id, Some("dependency-world"))?;
65+
// let remap = base_resolve.merge(dependency_resolve.clone())?;
66+
// let dependecy_world_id = remap.map_world(dependecy_main_world_id, None)?;
67+
// base_resolve.merge_worlds(dependecy_world_id, base_resolve_world_id)?;
7668

77-
Ok((base_resolve, base_resolve_pkg_id))
78-
}
69+
// Ok((base_resolve, base_resolve_pkg_id))
70+
// }

src/language/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod rust;

src/language/rust.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn identifier_safe(package_name: &wit_parser::PackageName) -> String {
2+
format!("{ns}_{name}", ns = package_name.namespace, name = package_name.name)
3+
}

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clap::{Parser, Subcommand};
33

44
mod commands;
55
mod common;
6+
mod language;
67
use commands::{add::AddCommand, bindings::GenerateBindingsCommand, publish::PublishCommand};
78

89
/// Main CLI structure for command-line argument parsing.

0 commit comments

Comments
 (0)