Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cpetig committed Jul 16, 2024
2 parents 7330c92 + fa19e08 commit 7fe9f8d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/csharp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test = false
wasm-encoder = { workspace = true }
wit-bindgen-core = { workspace = true }
wit-component = { workspace = true }
wit-parser = { workspace = true }
wasm-metadata = { workspace = true }
heck = { workspace = true }
clap = { workspace = true, optional = true }
Expand Down
47 changes: 46 additions & 1 deletion crates/csharp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use wit_bindgen_core::{
},
Files, InterfaceGenerator as _, Ns, WorldGenerator,
};
use wit_component::StringEncoding;
use wit_component::{StringEncoding, WitPrinter};
mod csproj;
pub use csproj::CSProject;

Expand Down Expand Up @@ -733,6 +733,51 @@ impl WorldGenerator for CSharp {
);
}

// For the time being, we generate both a .wit file and a .o file to
// represent the component type. Newer releases of the .NET runtime
// will be able to use the former, but older ones will need the
// latter.
//
// TODO: stop generating the .o file once a new-enough release is
// available for us to test using only the .wit file.

{
// When generating a WIT file, we first round-trip through the
// binary encoding. This has the effect of flattening any
// `include`d worlds into the specified world and excluding
// unrelated worlds, ensuring the output WIT contains no extra
// information beyond what the binary representation contains.
//
// This is important because including more than one world in
// the output would make it ambigious, and since this file is
// intended to be used non-interactively at link time, the
// linker will have no additional information to resolve such
// ambiguity.
let (resolve, _) =
wit_parser::decoding::decode_world(&wit_component::metadata::encode(
&resolve,
id,
self.opts.string_encoding,
None,
)?)?;

files.push(
&format!("{world_namespace}_component_type.wit"),
WitPrinter::default()
.emit_docs(false)
.print(
&resolve,
&resolve
.packages
.iter()
.map(|(id, _)| id)
.collect::<Vec<_>>(),
false,
)?
.as_bytes(),
);
}

files.push(
&format!("{world_namespace}_component_type.o",),
component_type_object::object(resolve, id, self.opts.string_encoding)
Expand Down

0 comments on commit 7fe9f8d

Please sign in to comment.