Skip to content

Commit

Permalink
Fixup for golang extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyaxod committed Sep 22, 2023
1 parent 6dbb46a commit 023eaf5
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion extension/generator/golang/generated.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Code generated by scale-signature v0.3.20, DO NOT EDIT.
// Code generated by scale-signature v0.4.1, DO NOT EDIT.
// output: types

package types
Expand Down
8 changes: 4 additions & 4 deletions extension/generator/golang/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,29 @@ func TestGenerator(t *testing.T) {

formatted, err := GenerateTypes(s, "types")
require.NoError(t, err)
// os.WriteFile("./generated.txt", formatted, 0644)
// os.WriteFile("./generated.txt", formatted, 0644)

expTypes, err := os.ReadFile("./generated.txt")
require.NoError(t, err)
require.Equal(t, string(expTypes), string(formatted))

host, err := GenerateHost(s, packageName, "v0.1.0")
require.NoError(t, err)
// os.WriteFile("./host.txt", host, 0644)
// os.WriteFile("./host.txt", host, 0644)
expHost, err := os.ReadFile("./host.txt")
require.NoError(t, err)
require.Equal(t, string(expHost), string(host))

guest, err := GenerateGuest(s, packageName, "v0.1.0")
require.NoError(t, err)
// os.WriteFile("./guest.txt", guest, 0644)
// os.WriteFile("./guest.txt", guest, 0644)
expGuest, err := os.ReadFile("./guest.txt")
require.NoError(t, err)
require.Equal(t, string(expGuest), string(guest))

mod, err := GenerateModfile(packageName)
require.NoError(t, err)
// os.WriteFile("./modfile.txt", mod, 0644)
// os.WriteFile("./modfile.txt", mod, 0644)
expMod, err := os.ReadFile("./modfile.txt")
require.NoError(t, err)
require.Equal(t, string(expMod), string(mod))
Expand Down
2 changes: 1 addition & 1 deletion extension/generator/golang/guest.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Code generated by scale-signature-go v0.1.0, DO NOT EDIT.
// Code generated by scale-extension v0.1.0, DO NOT EDIT.
// schema: HttpFetch:alpha
// output: extfetch

Expand Down
6 changes: 3 additions & 3 deletions extension/generator/golang/host.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Code generated by scale-signature-go v0.1.0, DO NOT EDIT.
// Code generated by scale-extension v0.1.0, DO NOT EDIT.
// schema: HttpFetch:alpha
// output: extfetch

Expand All @@ -10,7 +10,7 @@ import (
"sync"
"sync/atomic"

"github.com/loopholelabs/scale/extension"
extension "github.com/loopholelabs/scale-extension-interfaces"
)

const identifier = "HttpFetch:alpha"
Expand Down Expand Up @@ -47,7 +47,7 @@ func (he *hostExt) Reset() {

}

func New(impl HttpFetchIfc) extension.HostExtension {
func New(impl HttpFetchIfc) extension.Extension {
hostWrapper := &HttpFetchHost{impl: impl}

fns := make(map[string]extension.InstallableFunc)
Expand Down
2 changes: 1 addition & 1 deletion extension/generator/golang/interfaces.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Code generated by scale-signature-go v0.1.0, DO NOT EDIT.
// Code generated by scale-extension v0.1.0, DO NOT EDIT.
// schema: HttpFetch:alpha
// output: extfetch

Expand Down
2 changes: 1 addition & 1 deletion extension/generator/golang/modfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ go 1.20

require (
github.com/loopholelabs/polyglot v1.1.3
github.com/loopholelabs/scale-signature-interfaces v0.1.7
github.com/loopholelabs/scale-extension-interfaces v0.1.0
)
2 changes: 1 addition & 1 deletion extension/generator/golang/templates/guest.go.templ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Code generated by scale-signature-go {{ .version }}, DO NOT EDIT.
// Code generated by scale-extension {{ .version }}, DO NOT EDIT.
// schema: {{ .schema.Name }}:{{ .schema.Tag }}
// output: {{ .package }}

Expand Down
2 changes: 1 addition & 1 deletion extension/generator/golang/templates/host.go.templ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Code generated by scale-signature-go {{ .version }}, DO NOT EDIT.
// Code generated by scale-extension {{ .version }}, DO NOT EDIT.
// schema: {{ .schema.Name }}:{{ .schema.Tag }}
// output: {{ .package }}

Expand Down
2 changes: 1 addition & 1 deletion extension/generator/golang/templates/interfaces.go.templ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Code generated by scale-signature-go {{ .version }}, DO NOT EDIT.
// Code generated by scale-extension {{ .version }}, DO NOT EDIT.
// schema: {{ .schema.Name }}:{{ .schema.Tag }}
// output: {{ .package }}

Expand Down
12 changes: 12 additions & 0 deletions storage/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ func GenerateExtension(ext *extension.Schema, name string, tag string, org strin
return err
}

err = os.MkdirAll(path.Join(directory, "rust", "guest"), 0755)
if err != nil {
return err
}

err = os.MkdirAll(path.Join(directory, "golang", "host"), 0755)
if err != nil {
return err
Expand All @@ -322,6 +327,13 @@ func GenerateExtension(ext *extension.Schema, name string, tag string, org strin
}
}

for _, file := range guestPackage.RustFiles {
err = os.WriteFile(path.Join(directory, "rust", "guest", file.Path()), file.Data(), 0644)
if err != nil {
return err
}
}

hostPackage, err := generator.GenerateHostLocal(&generator.Options{
Extension: ext,
GolangPackageImportPath: "extension",
Expand Down

0 comments on commit 023eaf5

Please sign in to comment.