Skip to content

Commit 6a72f5b

Browse files
authored
build: Migrate from TinyGo to Go 1.21 (#5)
1 parent e9a28f2 commit 6a72f5b

File tree

13 files changed

+51
-630
lines changed

13 files changed

+51
-630
lines changed

.github/workflows/ci.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@ jobs:
1212
- uses: actions/checkout@v3
1313
- uses: actions/setup-go@v4
1414
with:
15-
go-version: '1.19'
16-
- run: wget https://github.com/tinygo-org/tinygo/releases/download/v0.26.0/tinygo_0.26.0_amd64.deb
17-
- run: sudo dpkg -i tinygo_0.26.0_amd64.deb
15+
go-version: '1.21.0-rc.2'
1816
- run: make

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ sqlc-gen-kotlin:
44
cd plugin && go build -o ~/bin/sqlc-gen-kotlin ./main.go
55

66
sqlc-gen-kotlin.wasm:
7-
cd plugin && tinygo build -o sqlc-gen-kotlin.wasm -gc=leaking -scheduler=none -wasm-abi=generic -target=wasi main.go
7+
cd plugin && GOOS=wasip1 GOARCH=wasm go build -o sqlc-gen-kotlin.wasm main.go
88
openssl sha256 plugin/sqlc-gen-kotlin.wasm
99

go.mod

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ module github.com/tabbed/sqlc-gen-kotlin
33
go 1.19
44

55
require (
6+
buf.build/gen/go/sqlc/sqlc/protocolbuffers/go v1.30.0-20230621221448-196413f69ab3.1
67
github.com/jinzhu/inflection v1.0.0
7-
github.com/mailru/easyjson v0.7.7
8-
github.com/tabbed/sqlc-go v1.16.0
8+
github.com/tabbed/sqlc-go v1.18.0
99
)
1010

11-
require (
12-
github.com/josharian/intern v1.0.0 // indirect
13-
google.golang.org/protobuf v1.28.1 // indirect
14-
)
11+
require google.golang.org/protobuf v1.30.0 // indirect

go.sum

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1+
buf.build/gen/go/sqlc/sqlc/protocolbuffers/go v1.30.0-20230621221448-196413f69ab3.1 h1:ze0HODAjPRXSkiqSpDTYq2baS4IVtRtDLSZY2p1ZCX4=
2+
buf.build/gen/go/sqlc/sqlc/protocolbuffers/go v1.30.0-20230621221448-196413f69ab3.1/go.mod h1:DSpReHp8PwHOeCfGymiiY4HSx2iVL358X7JRMciL7T0=
13
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
24
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
35
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
46
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
57
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
6-
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
7-
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
8-
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
9-
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
10-
github.com/tabbed/sqlc-go v1.16.0 h1:EwPBXdGn5tyrLjcNiHRoQthWvJeF5NjG9Cx1WK5iFsY=
11-
github.com/tabbed/sqlc-go v1.16.0/go.mod h1:mqMU5duZRGz5Wp/qJXwkERf+MXgGOZ8BmW/tH9KyvWA=
8+
github.com/tabbed/sqlc-go v1.18.0 h1:GNE8b8xue8fKVptQnr3Z6DV8FqdokyDYML7O0kYtbe4=
9+
github.com/tabbed/sqlc-go v1.18.0/go.mod h1:qx8ocsmviBDyRfLNuJQtdu0f5oqa8XBjKxMldl+Wm24=
1210
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
1311
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
14-
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
15-
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
12+
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
13+
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=

internal/core/config_easyjson.go

-131
This file was deleted.

internal/core/gen.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strconv"
1010
"strings"
1111

12-
plugin "github.com/tabbed/sqlc-go/codegen"
12+
"buf.build/gen/go/sqlc/sqlc/protocolbuffers/go/protos/plugin"
1313
"github.com/tabbed/sqlc-go/metadata"
1414
"github.com/tabbed/sqlc-go/sdk"
1515

internal/core/imports.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"sort"
55
"strings"
66

7-
plugin "github.com/tabbed/sqlc-go/codegen"
7+
"buf.build/gen/go/sqlc/sqlc/protocolbuffers/go/protos/plugin"
88
)
99

1010
type Importer struct {

internal/core/mysql_type.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package core
22

33
import (
4-
plugin "github.com/tabbed/sqlc-go/codegen"
4+
"buf.build/gen/go/sqlc/sqlc/protocolbuffers/go/protos/plugin"
55
"github.com/tabbed/sqlc-go/sdk"
66
)
77

internal/core/postgresql_type.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package core
33
import (
44
"log"
55

6-
plugin "github.com/tabbed/sqlc-go/codegen"
6+
"buf.build/gen/go/sqlc/sqlc/protocolbuffers/go/protos/plugin"
77
"github.com/tabbed/sqlc-go/sdk"
88
)
99

internal/gen.go

+36-11
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,34 @@ import (
44
"bufio"
55
"bytes"
66
"context"
7-
"io"
7+
_ "embed"
8+
"encoding/json"
89
"strings"
10+
"text/template"
911

10-
easyjson "github.com/mailru/easyjson"
11-
plugin "github.com/tabbed/sqlc-go/codegen"
12+
"buf.build/gen/go/sqlc/sqlc/protocolbuffers/go/protos/plugin"
1213

1314
"github.com/tabbed/sqlc-gen-kotlin/internal/core"
14-
"github.com/tabbed/sqlc-gen-kotlin/internal/tmpl"
15+
"github.com/tabbed/sqlc-go/sdk"
1516
)
1617

17-
func Generate(ctx context.Context, req *plugin.Request) (*plugin.Response, error) {
18+
//go:embed tmpl/ktmodels.tmpl
19+
var ktModelsTmpl string
20+
21+
//go:embed tmpl/ktsql.tmpl
22+
var ktSqlTmpl string
23+
24+
//go:embed tmpl/ktiface.tmpl
25+
var ktIfaceTmpl string
26+
27+
func Offset(v int) int {
28+
return v + 1
29+
}
30+
31+
func Generate(ctx context.Context, req *plugin.CodeGenRequest) (*plugin.CodeGenResponse, error) {
1832
var conf core.Config
1933
if len(req.PluginOptions) > 0 {
20-
if err := easyjson.Unmarshal(req.PluginOptions, &conf); err != nil {
34+
if err := json.Unmarshal(req.PluginOptions, &conf); err != nil {
2135
return nil, err
2236
}
2337
}
@@ -36,6 +50,17 @@ func Generate(ctx context.Context, req *plugin.Request) (*plugin.Response, error
3650
Queries: queries,
3751
}
3852

53+
funcMap := template.FuncMap{
54+
"lowerTitle": sdk.LowerTitle,
55+
"comment": sdk.DoubleSlashComment,
56+
"imports": i.Imports,
57+
"offset": Offset,
58+
}
59+
60+
modelsFile := template.Must(template.New("table").Funcs(funcMap).Parse(ktModelsTmpl))
61+
sqlFile := template.Must(template.New("table").Funcs(funcMap).Parse(ktSqlTmpl))
62+
ifaceFile := template.Must(template.New("table").Funcs(funcMap).Parse(ktIfaceTmpl))
63+
3964
core.DefaultImporter = i
4065

4166
tctx := core.KtTmplCtx{
@@ -50,11 +75,11 @@ func Generate(ctx context.Context, req *plugin.Request) (*plugin.Response, error
5075

5176
output := map[string]string{}
5277

53-
execute := func(name string, f func(io.Writer, core.KtTmplCtx) error) error {
78+
execute := func(name string, t *template.Template) error {
5479
var b bytes.Buffer
5580
w := bufio.NewWriter(&b)
5681
tctx.SourceName = name
57-
err := f(w, tctx)
82+
err := t.Execute(w, tctx)
5883
w.Flush()
5984
if err != nil {
6085
return err
@@ -66,13 +91,13 @@ func Generate(ctx context.Context, req *plugin.Request) (*plugin.Response, error
6691
return nil
6792
}
6893

69-
if err := execute("Models.kt", tmpl.KtModels); err != nil {
94+
if err := execute("Models.kt", modelsFile); err != nil {
7095
return nil, err
7196
}
72-
if err := execute("Queries.kt", tmpl.KtIface); err != nil {
97+
if err := execute("Queries.kt", ifaceFile); err != nil {
7398
return nil, err
7499
}
75-
if err := execute("QueriesImpl.kt", tmpl.KtSQL); err != nil {
100+
if err := execute("QueriesImpl.kt", sqlFile); err != nil {
76101
return nil, err
77102
}
78103

0 commit comments

Comments
 (0)