-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
V8 macOS Builder
committed
Feb 3, 2023
1 parent
5fa6663
commit 2be51e6
Showing
26 changed files
with
638 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"go/ast" | ||
"go/parser" | ||
"go/token" | ||
|
||
"os" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
// generate rtti | ||
// generate typescript types | ||
// generate adapters for different interfaces | ||
// magic comments in the parser | ||
var fileSet token.FileSet | ||
if wd, err := os.Getwd(); err != nil { | ||
panic(err) | ||
} else if packages, err := parser.ParseDir(&fileSet, wd, nil, parser.ParseComments|parser.AllErrors); err != nil { | ||
panic(err) | ||
} else { | ||
tags := []string{"js"} | ||
for _, pkg := range packages { | ||
for f, a := range pkg.Files { | ||
if text, err := os.ReadFile(f); err != nil { | ||
panic(err) | ||
} else { | ||
nodes := FindDeclarationCommentTags(string(text), tags, a) | ||
|
||
for _, node := range nodes { | ||
fmt.Println(node) | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
func FindDeclarationCommentTags(file string, tags []string, a *ast.File) []*TaggedNode { | ||
decls := []*TaggedNode{} | ||
for _, comments := range a.Comments { | ||
declTags := []Tag{} | ||
for _, comment := range comments.List { | ||
for _, tag := range tags { | ||
text := strings.TrimSpace(strings.TrimPrefix(comment.Text, "//")) | ||
if strings.HasPrefix(text, tag+":") { | ||
declTags = append(declTags, Tag{ | ||
Name: tag, | ||
Text: strings.TrimSpace(strings.TrimPrefix(text, tag+":")), | ||
}) | ||
} | ||
} | ||
} | ||
|
||
if len(declTags) > 0 { | ||
endPos := comments.End() | ||
ast.Inspect(a, func(node ast.Node) bool { | ||
if node == nil { | ||
return false | ||
} | ||
|
||
if node.Pos() > endPos && strings.TrimSpace(file[endPos:node.Pos()]) == "" { | ||
record := false | ||
if _, ok := node.(*ast.StructType); ok { | ||
|
||
record = true | ||
} else if _, ok := node.(*ast.File); ok { | ||
record = true | ||
} else if _, ok := node.(*ast.FuncDecl); ok { | ||
record = true | ||
} else if _, ok := node.(*ast.Field); ok { | ||
record = true | ||
} | ||
|
||
if record { | ||
d := &TaggedNode{ | ||
Tags: declTags, | ||
Node: node, | ||
} | ||
decls = append(decls, d) | ||
return false | ||
} else { | ||
endPos = node.End() | ||
} | ||
} | ||
return true | ||
}) | ||
} | ||
|
||
} | ||
|
||
return decls | ||
} | ||
|
||
type Tag struct { | ||
Name string | ||
Text string | ||
} | ||
|
||
func (t *Tag) String() string { | ||
return fmt.Sprintf("%s:%s", t.Name, t.Text) | ||
} | ||
|
||
type TaggedNode struct { | ||
Tags []Tag | ||
Node ast.Node | ||
} | ||
|
||
func (t *TaggedNode) String() string { | ||
out := []string{} | ||
for _, tag := range t.Tags { | ||
out = append(out, tag.String()) | ||
} | ||
|
||
node := "" | ||
|
||
if v, ok := t.Node.(*ast.File); ok { | ||
node = fmt.Sprintf("go package %s", v.Name) | ||
} else if v, ok := t.Node.(*ast.TypeSpec); ok { | ||
node = fmt.Sprintf("go struct %s", v) | ||
} else if v, ok := t.Node.(*ast.Field); ok { | ||
node = fmt.Sprintf("go field %s %s", v.Names[0], v.Type.(*ast.SelectorExpr).Sel) | ||
} else if v, ok := t.Node.(*ast.FuncDecl); ok { | ||
node = fmt.Sprintf("go func %s", v.Name) | ||
} else { | ||
node = fmt.Sprintf("%s", t.Node) | ||
} | ||
|
||
return fmt.Sprintf("%s\n%v", strings.Join(out, "\n"), node) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/grexie/isolates | ||
|
||
go 1.17 | ||
go 1.18 | ||
|
||
require ( | ||
github.com/grexie/refutils v0.1.1 | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash -e | ||
|
||
VERSION=$1 | ||
VERSION=${VERSION:-10.4.132.23} | ||
SCHEME=$2 | ||
SCHEME=${SCHEME:-release} | ||
|
||
DIR=/usr/local/include/v8 | ||
rm -Rf ${DIR} | ||
mkdir -p ${DIR} | ||
URL=https://github.com/grexie/v8-builder/releases/download/${VERSION}/v8-headers-${VERSION}.zip | ||
cd ${DIR} | ||
curl -sSL ${URL} -o v8-headers.zip | ||
test -f v8-headers.zip && unzip v8-headers.zip 2>/dev/null >/dev/null && echo "Installed v8-headers-${VERSION}" || true | ||
rm -f v8-headers.zip | ||
|
||
for PLATFORM in macos linux android windows; do | ||
for ARCH in arm64 x64 x86 arm; do | ||
DIR=/usr/local/lib/v8/${ARCH}/${PLATFORM} | ||
rm -Rf ${DIR} | ||
mkdir -p ${DIR} | ||
URL=https://github.com/grexie/v8-builder/releases/download/${VERSION}/v8-${PLATFORM}-${ARCH}-${SCHEME}-${VERSION}.zip | ||
cd ${DIR} | ||
curl -sSL ${URL} -o v8.zip | ||
test -f v8.zip && unzip -j v8.zip 2>/dev/null >/dev/null && echo "Installed v8-${VERSION} for ${PLATFORM} ${ARCH} (${SCHEME})" || true | ||
rm -f v8.zip | ||
done | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
_ "embed" | ||
"io" | ||
"log" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
//go:embed install-v8.sh | ||
var script []byte | ||
|
||
func main() { | ||
args := append([]string{"-es", "-"}, os.Args[1:]...) | ||
cmd := exec.Command("/bin/bash", args...) | ||
stdout, _ := cmd.StdoutPipe() | ||
stderr, _ := cmd.StderrPipe() | ||
stdin, _ := cmd.StdinPipe() | ||
cmd.Start() | ||
go io.Copy(os.Stdout, stdout) | ||
go io.Copy(os.Stderr, stderr) | ||
stdin.Write(script) | ||
stdin.Close() | ||
if err := cmd.Wait(); err != nil { | ||
log.Println(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.