@@ -21,6 +21,7 @@ import (
21
21
"go.bytecodealliance.org/internal/codec"
22
22
"go.bytecodealliance.org/internal/go/gen"
23
23
"go.bytecodealliance.org/internal/stringio"
24
+ "go.bytecodealliance.org/internal/wasm"
24
25
"go.bytecodealliance.org/wit"
25
26
"go.bytecodealliance.org/wit/logging"
26
27
)
@@ -2327,34 +2328,45 @@ func (g *generator) newPackage(w *wit.World, i *wit.Interface, name string) (*ge
2327
2328
// Component Model types and functions imported into and/or exported
2328
2329
// from this Go package.
2329
2330
if false {
2330
- // Synthesize a unique-ish library name
2331
- lib := id .String ()
2331
+ // Synthesize a unique-ish name
2332
+ worldName := id .String ()
2332
2333
if name != id .Extension {
2333
- lib += "-" + name
2334
- }
2335
- lib = strings .ReplaceAll (lib , "/" , "-" )
2336
- lib = strings .ReplaceAll (lib , ":" , "-" )
2337
- libFile := pkg .File ("lib" + lib + ".a" )
2338
-
2339
- // Generate
2340
- witText := g .res .WIT (wit .Filter (w , i ), "" )
2341
- witFile := g .witFileFor (owner )
2342
- witFile .WriteString (witText )
2334
+ worldName += "-" + name
2335
+ }
2336
+ worldName += "-go"
2337
+ worldName = replacer .Replace (worldName )
2338
+ // libFile := pkg.File("lib" + lib + ".a")
2339
+ sysoFile := pkg .File (worldName + ".wasm.syso" )
2340
+
2341
+ // Generate wasm file
2342
+ world := w .Clone ()
2343
+ world .Name = worldName
2344
+ w .Package .Worlds .Set (worldName , world )
2345
+ witText := g .res .WIT (wit .Filter (world , i ), "" )
2346
+ w .Package .Worlds .Delete (worldName )
2347
+ // witFile := g.witFileFor(owner)
2348
+ // witFile.WriteString(witText)
2343
2349
content , err := g .componentEmbed (witText )
2344
2350
if err != nil {
2345
- // return nil, err
2351
+ return nil , err
2346
2352
}
2347
- libFile .Write (content )
2353
+ componentType := & wasm.CustomSection {
2354
+ Name : "component-type:" + worldName ,
2355
+ Contents : content ,
2356
+ }
2357
+ wasm .Write (sysoFile , []wasm.Section {& wasm.LinkingSection {}, componentType })
2348
2358
2349
2359
// Write Cgo file
2350
- cgoFile := g .cgoFileFor (owner )
2351
- stringio .Write (cgoFile , "// #cgo LDFLAGS: -L. -l" , lib , "\n " )
2352
- stringio .Write (cgoFile , "import \" C\" \n " )
2360
+ // cgoFile := g.cgoFileFor(owner)
2361
+ // stringio.Write(cgoFile, "// #cgo LDFLAGS: -L. -l", lib, "\n")
2362
+ // stringio.Write(cgoFile, "import \"C\"\n")
2353
2363
}
2354
2364
2355
2365
return pkg , nil
2356
2366
}
2357
2367
2368
+ var replacer = strings .NewReplacer ("/" , "-" , ":" , "-" , "@" , "-v" , "." , "" )
2369
+
2358
2370
// componentEmbed runs generated WIT through wasm-tools to generate a wasm file with a component-type custom section.
2359
2371
func (g * generator ) componentEmbed (witData string ) ([]byte , error ) {
2360
2372
// TODO: --all-features?
0 commit comments