Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Reworked app manifest #95

Merged
merged 109 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
ce28aa5
WIP: use wit_encoder for removing imports
noise64 Oct 21, 2024
5619d5c
WIP: fixing add_dep tests
noise64 Oct 23, 2024
5829b44
cleanup
noise64 Oct 23, 2024
f8a456c
cleanup
noise64 Oct 23, 2024
6af16ef
WIP: temp fix for inlined circular imports
noise64 Oct 23, 2024
ca57b49
fmt
noise64 Oct 23, 2024
97c38db
import stubs
noise64 Oct 23, 2024
49340dd
import stubs test cleanups
noise64 Oct 23, 2024
c4161d3
cleanup
noise64 Oct 25, 2024
5727157
add test for using types with the same name from different interfaces
noise64 Oct 25, 2024
e460c47
add nested "reexport" case
noise64 Oct 25, 2024
5b41f50
fix naming
noise64 Oct 25, 2024
d7b1756
logging / cleanups
noise64 Oct 25, 2024
468177f
even more reexport example
noise64 Oct 25, 2024
64ea031
add missing hunk for package_id
noise64 Oct 25, 2024
becbaab
add missing hunk for package_id
noise64 Oct 26, 2024
50aebff
even more conflict for many exports
noise64 Oct 26, 2024
27cee9e
use latest (forked version) of wasm-tools and use PackageSourceMap in…
noise64 Oct 28, 2024
b347172
cleanups
noise64 Oct 28, 2024
cc169c2
cleanups
noise64 Oct 28, 2024
afb86cb
use wit_encode for wit generation
noise64 Oct 29, 2024
aeda02f
fix alias to alias, comments
noise64 Oct 29, 2024
0e9e51b
clippy
noise64 Oct 29, 2024
303b41f
extract StubConfig
noise64 Oct 30, 2024
ac7d5fa
remove conf param
noise64 Oct 30, 2024
1b85076
update add_dep test for StubConfig
noise64 Oct 30, 2024
7d05cba
drop package visitor, as it doesnt help much
noise64 Oct 30, 2024
7e7d392
more cleanups, extract EncodedWitDir
noise64 Oct 30, 2024
da4f522
delete test code
noise64 Oct 30, 2024
e815f64
add extract_main_interface_package
noise64 Oct 30, 2024
e06060b
rename
noise64 Oct 31, 2024
cb9a964
add comments for extract_main_interface_package
noise64 Oct 31, 2024
edf4c6f
checkpoint before dropping full compat: transform cleanups, move add_…
noise64 Oct 31, 2024
8f5eb9f
remove debug code
noise64 Oct 31, 2024
12adae2
use extracted interface packages and remove inlining, make overwritin…
noise64 Nov 5, 2024
06c6977
add option in StubDef::new to apply interface packages extract
noise64 Nov 5, 2024
4231fb8
cleanup leftover "auto" imports
noise64 Nov 5, 2024
79a9ed9
clippy, fmt
noise64 Nov 5, 2024
e3edd84
fix cargo gen / tests
noise64 Nov 5, 2024
576d274
separate input and output build for declarative build, add ResolvedWi…
noise64 Nov 7, 2024
d354910
cleanups
noise64 Nov 7, 2024
4f4a6fa
pre build cleanup
noise64 Nov 7, 2024
7eef138
cleanup / allow skip by content
noise64 Nov 11, 2024
81dfdfc
collect input deps by referenced, contained, component
noise64 Nov 11, 2024
4341ca4
fix test
noise64 Nov 11, 2024
405586c
pre-component-build: build by interface dep order and add interface deps
noise64 Nov 12, 2024
9713ad1
delete all stub targets
noise64 Nov 12, 2024
05717f9
WIP: package deps
noise64 Nov 12, 2024
6d6db5c
clippy, fmt
noise64 Nov 12, 2024
7446a48
clean: delete wasm input and output
noise64 Nov 12, 2024
8e530f9
declarative rust fixes
noise64 Nov 12, 2024
da9c62d
plug fix
noise64 Nov 12, 2024
5e8e794
move wit test data, add placeholder for dec app build integ tests
noise64 Nov 13, 2024
8f6a97b
leftover
noise64 Nov 13, 2024
f72eef7
move validation to src from model
noise64 Nov 14, 2024
de67dd0
add new type for ComponentName and cleanup LogColorize
noise64 Nov 14, 2024
2057f13
fs cleanups
noise64 Nov 14, 2024
938aec1
clippy
noise64 Nov 14, 2024
0ea09c7
cleanup
noise64 Nov 14, 2024
96db313
fs fixes and cleanups
noise64 Nov 14, 2024
951fa54
move to src from commands
noise64 Nov 14, 2024
438d81e
transitive resolve for package deps
noise64 Nov 14, 2024
bc57c34
fix test data path
noise64 Nov 14, 2024
7c5d0d4
transitive resolve for package deps for building base output wit dir
noise64 Nov 14, 2024
5d961b5
fix compose wasm read
noise64 Nov 14, 2024
1608023
error and logging fixes
noise64 Nov 14, 2024
e2b8e76
fix stub-wasm test
noise64 Nov 14, 2024
a2789df
log message
noise64 Nov 14, 2024
aa2ae4c
validate conflicting package names
noise64 Nov 14, 2024
d34b40c
cleanups
noise64 Nov 15, 2024
84e0280
mark generated dirs with a marker file
noise64 Nov 15, 2024
494af7c
error format
noise64 Nov 15, 2024
3d06694
clippy
noise64 Nov 15, 2024
7256838
log format
noise64 Nov 17, 2024
6b3f266
interface extraction: fix exporting / importing the same interface
noise64 Nov 18, 2024
d2a7114
use id for dep order building, collect loops properly
noise64 Nov 19, 2024
5696a32
highlight
noise64 Nov 19, 2024
f2d5313
clippy
noise64 Nov 19, 2024
0847d4c
build profiles and component templates
noise64 Nov 21, 2024
6181c51
WIP: reworking profiles
noise64 Nov 22, 2024
d63e6f0
cleanup
noise64 Nov 22, 2024
465e8c9
always choose profile, even if it is not matching the requested one
noise64 Nov 22, 2024
c4fe6eb
fix clean to support profiles
noise64 Nov 22, 2024
ab3a8b6
up-to-date coloring
noise64 Nov 22, 2024
44cadee
extract wasm component prop validation
noise64 Nov 22, 2024
51a2259
custom commands and clean targets
noise64 Nov 22, 2024
2e7f059
custom commands and clean targets
noise64 Nov 22, 2024
036ff1e
fix custom command listing
noise64 Nov 22, 2024
c6905cc
cleanup
noise64 Nov 22, 2024
523eb10
format
noise64 Nov 22, 2024
b0136c6
cleanup
noise64 Nov 22, 2024
8ef65e7
add new app manifest schema / delete leftover example
noise64 Nov 25, 2024
14470df
WIP: switching to new schema
noise64 Dec 1, 2024
e402e89
model cleanups
noise64 Dec 1, 2024
009622a
cleanups / fixes
noise64 Dec 1, 2024
07c97f3
fix regenerate_cargo_package_component
noise64 Dec 2, 2024
3ff0533
cleanups / offline mode
noise64 Dec 2, 2024
6d960a0
format / use official wasm-tools
noise64 Dec 3, 2024
ee5d22b
bump wac-graph
noise64 Dec 3, 2024
986771e
bump wac-graph, add missing lock
noise64 Dec 3, 2024
8a0a667
property extensions
noise64 Dec 3, 2024
d5cf6f7
pub ApplicationContext
noise64 Dec 3, 2024
019c497
component validation and extension conversion
noise64 Dec 3, 2024
60c28ed
cleanups
noise64 Dec 3, 2024
1bf1a58
add source to extensions convert
noise64 Dec 3, 2024
bec5871
clippy + expose app ctx new
noise64 Dec 3, 2024
ef6f855
expose app ctx fields
noise64 Dec 3, 2024
d8000ba
make app command optional, clippy, remove custom command "about" for now
noise64 Dec 3, 2024
28344b8
bump fallback version (workaround for branch dep)
noise64 Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use extracted interface packages and remove inlining, make overwritin…
…g the default
noise64 committed Nov 5, 2024
commit 12adae247ebd67d0a9139f9d68ac636bf6a13f85
8 changes: 3 additions & 5 deletions wasm-rpc-stubgen/src/cargo.rs
Original file line number Diff line number Diff line change
@@ -97,11 +97,9 @@ pub fn generate_cargo_toml(def: &StubDefinition) -> anyhow::Result<()> {
wit_dependencies.insert(
format_package_name_without_version(&def.source_package_name),
WitDependency {
path: naming::wit::package_wit_dep_dir_from_package_name(
&def.source_package_name,
)
.to_string_lossy()
.to_string(),
path: naming::wit::package_wit_dep_dir_from_parser(&def.source_package_name)
.to_string_lossy()
.to_string(),
},
);
} else {
3 changes: 0 additions & 3 deletions wasm-rpc-stubgen/src/commands/declarative.rs
Original file line number Diff line number Diff line change
@@ -85,7 +85,6 @@ async fn pre_component_build_app(config: &Config, app: &Application) -> anyhow::
wasm_rpc_path_override: app.stub_wasm_rpc_path(&component_name),
wasm_rpc_version_override: app.stub_wasm_rpc_version(&component_name),
},
inline_source_types: app.stub_always_inline_types(&component_name),
})
.context("Failed to gather information for the stub generator")?;

@@ -131,8 +130,6 @@ async fn pre_component_build_app(config: &Config, app: &Application) -> anyhow::
add_stub_as_dependency_to_wit_dir(AddStubAsDepConfig {
stub_wit_root: app.stub_wit(dep_component_name),
dest_wit_root: app.component_wit(component_name),
overwrite: true, // NOTE: in declarative mode we always use overwrite
remove_dest_imports: false,
update_cargo_toml: UpdateCargoToml::Update,
})?
}
3 changes: 0 additions & 3 deletions wasm-rpc-stubgen/src/commands/dependencies.rs
Original file line number Diff line number Diff line change
@@ -19,14 +19,11 @@ use std::path::Path;
pub fn add_stub_dependency(
stub_wit_root: &Path,
dest_wit_root: &Path,
overwrite: bool,
update_cargo_toml: UpdateCargoToml,
) -> anyhow::Result<()> {
wit_generate::add_stub_as_dependency_to_wit_dir(AddStubAsDepConfig {
stub_wit_root: stub_wit_root.to_path_buf(),
dest_wit_root: dest_wit_root.to_path_buf(),
overwrite,
remove_dest_imports: true,
update_cargo_toml,
})
}
4 changes: 0 additions & 4 deletions wasm-rpc-stubgen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ pub mod stub;
pub mod wit_encode;
pub mod wit_generate;
pub mod wit_resolve;
pub mod wit_transform;

use crate::stub::{StubConfig, StubDefinition};
use crate::wit_generate::UpdateCargoToml;
@@ -227,7 +226,6 @@ pub fn generate(args: GenerateArgs) -> anyhow::Result<()> {
selected_world: args.world,
stub_crate_version: args.stub_crate_version,
wasm_rpc_override: args.wasm_rpc_override,
inline_source_types: args.always_inline_types,
}
)
.context("Failed to gather information for the stub generator. Make sure source_wit_root has a valid WIT file.")?;
@@ -244,7 +242,6 @@ pub async fn build(args: BuildArgs) -> anyhow::Result<()> {
selected_world: args.world,
stub_crate_version: args.stub_crate_version,
wasm_rpc_override: args.wasm_rpc_override,
inline_source_types: args.always_inline_types,
})
.context("Failed to gather information for the stub generator")?;

@@ -255,7 +252,6 @@ pub fn add_stub_dependency(args: AddStubDependencyArgs) -> anyhow::Result<()> {
commands::dependencies::add_stub_dependency(
&args.stub_wit_root,
&args.dest_wit_root,
args.overwrite,
if args.update_cargo_toml {
UpdateCargoToml::Update
} else {
36 changes: 30 additions & 6 deletions wasm-rpc-stubgen/src/naming.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
pub mod wit {
use anyhow::bail;
use anyhow::{anyhow, bail};
use std::path::{Path, PathBuf};

pub static DEPS_DIR: &str = "deps";
pub static WIT_DIR: &str = "wit";

pub static STUB_WIT_FILE_NAME: &str = "_stub.wit";
pub static INTERFACE_WIT_FILE_NAME: &str = "_interface.wit";

pub fn stub_package_name(package_name: &wit_parser::PackageName) -> wit_parser::PackageName {
wit_parser::PackageName {
@@ -77,10 +78,31 @@ pub mod wit {
))
}

pub fn package_dep_dir_name(package_name: &wit_parser::PackageName) -> String {
pub fn stub_import_interface_prefix_from_stub_package_name(
stub_package: &wit_parser::PackageName,
) -> anyhow::Result<String> {
Ok(format!(
"{}:{}-interface/",
stub_package.namespace,
stub_package
.name
.clone()
.strip_suffix("-stub")
.ok_or_else(|| anyhow!(
"Expected \"-stub\" suffix in stub package name: {}",
stub_package.to_string()
))?
))
}

pub fn package_dep_dir_name_from_parser(package_name: &wit_parser::PackageName) -> String {
format!("{}_{}", package_name.namespace, package_name.name)
}

pub fn package_dep_dir_name_from_encoder(package_name: &wit_encoder::PackageName) -> String {
format!("{}_{}", package_name.namespace(), package_name.name())
}

pub fn package_merged_wit_name(package_name: &wit_parser::PackageName) -> String {
format!("{}_{}.wit", package_name.namespace, package_name.name)
}
@@ -89,9 +111,11 @@ pub mod wit {
Path::new(WIT_DIR).join(DEPS_DIR).join(package_dir_name)
}

pub fn package_wit_dep_dir_from_package_name(
package_name: &wit_parser::PackageName,
) -> PathBuf {
package_wit_dep_dir_from_package_dir_name(&package_dep_dir_name(package_name))
pub fn package_wit_dep_dir_from_parser(package_name: &wit_parser::PackageName) -> PathBuf {
package_wit_dep_dir_from_package_dir_name(&package_dep_dir_name_from_parser(package_name))
}

pub fn package_wit_dep_dir_from_encode(package_name: &wit_encoder::PackageName) -> PathBuf {
package_wit_dep_dir_from_package_dir_name(&package_dep_dir_name_from_encoder(package_name))
}
}
31 changes: 5 additions & 26 deletions wasm-rpc-stubgen/src/rust.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
// limitations under the License.

use crate::commands::log::log_action;
use crate::stub::{FunctionResultStub, FunctionStub, InterfaceStub, StubDefinition, StubTypeOwner};
use crate::stub::{FunctionResultStub, FunctionStub, InterfaceStub, StubDefinition};
use anyhow::anyhow;
use heck::{ToShoutySnakeCase, ToSnakeCase, ToUpperCamelCase};
use proc_macro2::{Ident, Span, TokenStream};
@@ -713,9 +713,8 @@ fn type_to_rust_ident(typ: &Type, def: &StubDefinition) -> anyhow::Result<TokenS
let mut path = Vec::new();
path.push(quote! { crate });
path.push(quote! { bindings });
let fixed_owner = def.fix_inlined_owner(type_def);
match &fixed_owner {
StubTypeOwner::Source(TypeOwner::World(world_id)) => {
match &type_def.owner {
TypeOwner::World(world_id) => {
let world = def.get_world(*world_id)?;
let package_id =
world.package.ok_or(anyhow!("world has no package"))?;
@@ -729,7 +728,7 @@ fn type_to_rust_ident(typ: &Type, def: &StubDefinition) -> anyhow::Result<TokenS
path.push(quote! { #ns_ident });
path.push(quote! { #name_ident });
}
StubTypeOwner::Source(TypeOwner::Interface(interface_id)) => {
TypeOwner::Interface(interface_id) => {
let interface = def.get_interface(*interface_id)?;
let package_id = interface
.package
@@ -751,27 +750,7 @@ fn type_to_rust_ident(typ: &Type, def: &StubDefinition) -> anyhow::Result<TokenS
path.push(quote! { #name_ident });
path.push(quote! { #interface_ident });
}
StubTypeOwner::Source(TypeOwner::None) => {}
StubTypeOwner::StubInterface => {
let root_ns = Ident::new(
&def.source_package_name.namespace.to_snake_case(),
Span::call_site(),
);
let root_name = Ident::new(
&format!("{}_stub", def.source_package_name.name.to_snake_case()),
Span::call_site(),
);
let stub_interface_name = format!("stub-{}", def.source_world_name());
let stub_interface_name = Ident::new(
&to_rust_ident(&stub_interface_name).to_snake_case(),
Span::call_site(),
);

path.push(quote! { exports });
path.push(quote! { #root_ns });
path.push(quote! { #root_name });
path.push(quote! { #stub_interface_name });
}
TypeOwner::None => {}
}
Ok(quote! { #(#path)::*::#typ })
}
80 changes: 2 additions & 78 deletions wasm-rpc-stubgen/src/stub.rs
Original file line number Diff line number Diff line change
@@ -33,7 +33,6 @@ pub struct StubConfig {
pub selected_world: Option<String>,
pub stub_crate_version: String,
pub wasm_rpc_override: WasmRpcOverride,
pub inline_source_types: bool,
}

/// All the gathered information for generating the stub crate.
@@ -169,40 +168,6 @@ impl StubDefinition {
ResolvedWitDir::new(&self.target_wit_root())
}

pub fn fix_inlined_owner(&self, typedef: &TypeDef) -> StubTypeOwner {
if self.is_inlined(typedef) {
StubTypeOwner::StubInterface
} else {
StubTypeOwner::Source(typedef.owner)
}
}

fn is_inlined(&self, typedef: &TypeDef) -> bool {
match &typedef.owner {
TypeOwner::Interface(interface_id) => {
if self.config.inline_source_types {
if let Some(resolved_owner_interface) =
self.resolve.interfaces.get(*interface_id)
{
if let Some(name) = resolved_owner_interface.name.as_ref() {
self.stub_imported_interfaces()
.iter()
.any(|interface| &interface.name == name)
} else {
false
}
} else {
false
}
} else {
false
}
}
TypeOwner::World(_) => true,
TypeOwner::None => false,
}
}

pub fn stub_imported_interfaces(&self) -> &Vec<InterfaceStub> {
self.stub_imported_interfaces.get_or_init(|| {
let WorldItemsByType {
@@ -304,41 +269,13 @@ impl StubDefinition {
None => format!("{}-{}", interface_name, type_name),
});

let inlined = self.config.inline_source_types
&& interface.package == Some(self.source_package_id);

let inlined_type_def = match type_def.kind {
TypeDefKind::Type(Type::Id(type_id)) if inlined => {
let mut type_def = self
.resolve
.types
.get(type_id)
.unwrap_or_else(|| {
panic!("Failed to get type def for inlining")
})
.clone();

// Alias to alias does not need inlining
if let TypeDefKind::Type(Type::Id(_)) = type_def.kind {
None
} else {
type_def.name =
type_name_alias.clone().or_else(|| Some(type_name.clone()));
Some(type_def)
}
}
_ => None,
};

InterfaceStubTypeDef {
package_id: interface.package,
type_id,
type_def,
inlined_type_def,
interface_identifier,
type_name: type_name.clone(),
type_name_alias,
inlined,
}
})
})
@@ -353,10 +290,9 @@ impl StubDefinition {

pub fn stub_dep_package_ids(&self) -> &HashSet<PackageId> {
self.stub_dep_package_ids.get_or_init(|| {
self.resolve
.packages
self.stub_used_type_defs()
.iter()
.map(|(package_id, _)| package_id)
.filter_map(|type_def| type_def.package_id)
.collect()
})
}
@@ -677,21 +613,15 @@ pub struct InterfaceStubTypeDef {
pub package_id: Option<PackageId>,
pub type_id: TypeId,
pub type_def: TypeDef,
pub inlined_type_def: Option<TypeDef>,
pub interface_identifier: String,
pub type_name: String,
pub type_name_alias: Option<String>,
pub inlined: bool,
}

impl InterfaceStubTypeDef {
pub fn stub_type_name(&self) -> &str {
self.type_name_alias.as_deref().unwrap_or(&self.type_name)
}

pub fn stub_type_def(&self) -> &TypeDef {
self.inlined_type_def.as_ref().unwrap_or(&self.type_def)
}
}

#[derive(Debug, Clone)]
@@ -774,9 +704,3 @@ impl FunctionResultStub {
}
}
}

#[derive(Debug, Clone)]
pub enum StubTypeOwner {
StubInterface,
Source(TypeOwner),
}
Loading