@@ -10,6 +10,7 @@ use wac_graph::EncodeOptions;
1010use wac_parser:: Document ;
1111use wac_types:: BorrowedPackageKey ;
1212use wac_types:: Package ;
13+ use wasm_metadata:: AddMetadata ;
1314
1415pub mod cli;
1516pub mod config;
@@ -168,7 +169,10 @@ pub fn build(output: PathBuf, entry_name: String, virtualenv: Option<PathBuf>) -
168169 let composed =
169170 compose_with_wasiless ( & temp_component_wasm_path, WASILESS_WASM , WRAP_WAC , & output) ?;
170171
171- fs:: write ( & output, composed)
172+ log:: info!( " Injecting Fastly metadata..." ) ;
173+ let annotated = inject_fastly_metadata ( composed) ?;
174+
175+ fs:: write ( & output, annotated)
172176 . with_context ( || format ! ( "Failed to write output: {}" , output. display( ) ) ) ?;
173177
174178 log:: debug!( "Composed output: {}" , output. display( ) ) ;
@@ -231,3 +235,56 @@ fn compose_with_wasiless(
231235
232236 Ok ( encoded)
233237}
238+
239+ /// Inject build tool metadata into the Wasm component's standard `producers`
240+ /// custom section.
241+ ///
242+ /// Follows the WebAssembly [Producers Section spec] field conventions:
243+ ///
244+ /// - `language: Python <version>` — the source language and the CPython
245+ /// version bundled by componentize-py. Update this when upgrading to a
246+ /// componentize-py release that bundles a different CPython version.
247+ /// - `sdk: fastly-compute-py <version>` — the SDK library the user's code is
248+ /// written against, analogous to `@fastly/js-compute` for the JS SDK.
249+ /// - `processed-by: componentize-py <version>` — the tool that performed the
250+ /// core Wasm transformation. `fastly-compute-py` also adds itself here as
251+ /// the build orchestrator.
252+ ///
253+ /// Note: the Fastly-proprietary `fastly.manifest.*` custom sections
254+ /// (language, version, service_id, etc.) are **not** written here. Those are
255+ /// injected during package ingestion, sourced from the `fastly.toml` manifest
256+ /// that the CLI bundles alongside the Wasm in the upload package.
257+ /// Dependency lists, build scripts, and machine info are similarly the CLI's
258+ /// responsibility via its `fastly_data` producers entry.
259+ ///
260+ /// [Producers Section spec]: https://github.com/WebAssembly/tool-conventions/blob/main/ProducersSection.md
261+ fn inject_fastly_metadata ( wasm : Vec < u8 > ) -> Result < Vec < u8 > > {
262+ let mut add_metadata = AddMetadata :: default ( ) ;
263+
264+ // Source language. The version is the CPython version bundled by
265+ // componentize-py — update this when upgrading to a componentize-py
266+ // release that bundles a different CPython version.
267+ add_metadata
268+ . language
269+ . push ( ( "Python" . to_owned ( ) , "3.14" . to_owned ( ) ) ) ;
270+
271+ // The SDK the user's code is written against.
272+ add_metadata. sdk . push ( (
273+ "fastly-compute-py" . to_owned ( ) ,
274+ env ! ( "CARGO_PKG_VERSION" ) . to_owned ( ) ,
275+ ) ) ;
276+
277+ // Tools that performed the Wasm transformation.
278+ add_metadata. processed_by . push ( (
279+ "componentize-py" . to_owned ( ) ,
280+ env ! ( "COMPONENTIZE_PY_VERSION" ) . to_owned ( ) ,
281+ ) ) ;
282+ add_metadata. processed_by . push ( (
283+ "fastly-compute-py" . to_owned ( ) ,
284+ env ! ( "CARGO_PKG_VERSION" ) . to_owned ( ) ,
285+ ) ) ;
286+
287+ add_metadata
288+ . to_wasm ( & wasm)
289+ . context ( "Failed to add producers metadata to Wasm component" )
290+ }
0 commit comments