Skip to content

Commit

Permalink
Regenerate proto to avoid conflicts with pg_query_go (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga authored Dec 1, 2023
1 parent f871a21 commit bbab8b1
Show file tree
Hide file tree
Showing 4 changed files with 8,394 additions and 7,848 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/wasilibs/go-pgquery
go 1.19

require (
github.com/golang/protobuf v1.5.3
github.com/google/go-cmp v0.5.5
github.com/wasilibs/wazerox v0.0.0-20231117065139-b3503f4aeff6
google.golang.org/protobuf v1.31.0
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/wasilibs/wazerox v0.0.0-20231117065139-b3503f4aeff6 h1:jwbU8u5TuXModzdEG4wI0g4FyuD7ROSttU86go5sPdU=
github.com/wasilibs/wazerox v0.0.0-20231117065139-b3503f4aeff6/go.mod h1:IQNVyA4d1hWIe23mlMMuqXjyWMdndgSlNx6FqBkwPsM=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
44 changes: 44 additions & 0 deletions magefiles/magefile.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
package main

import (
"bufio"
"net/http"
"os"
"path/filepath"

"github.com/magefile/mage/sh"

"github.com/wasilibs/magefiles" // mage:import
)

func init() {
magefiles.SetLibraryName("pgquery")
}

// GenerateProto generates Go stubs from the libpgquery proto file.
// We regenerate because even when Go packages are different, only
// a single instance of a type can be registered if with the same
// package and it should be allowed to import both this and pg_query_go
// for transition reasons.
func GenerateProto() error {
if err := os.MkdirAll("build", 0o755); err != nil {
return err
}

resp, err := http.Get("https://raw.githubusercontent.com/pganalyze/libpg_query/15-4.2.3/protobuf/pg_query.proto")
if err != nil {
return err
}
defer resp.Body.Close()

f, err := os.Create(filepath.Join("build", "pg_query_wasilibs.proto"))
if err != nil {
return err
}

s := bufio.NewScanner(resp.Body)
for s.Scan() {
if s.Text() == "package pg_query;" {
_, _ = f.WriteString("package pg_query_wasilibs;\n")
continue
}
_, _ = f.WriteString(s.Text() + "\n")
}

if err := sh.RunV("go", "run", "github.com/curioswitch/protog/cmd@v0.3.0", "-I", "build", "--go_out=.", "--go_opt=Mpg_query_wasilibs.proto=/pg_query", "--go_opt=paths=source_relative", "build/pg_query_wasilibs.proto"); err != nil {
return err
}

return nil
}
Loading

0 comments on commit bbab8b1

Please sign in to comment.