summaryrefslogtreecommitdiff
path: root/build.go
diff options
context:
space:
mode:
Diffstat (limited to 'build.go')
-rw-r--r--build.go48
1 files changed, 45 insertions, 3 deletions
diff --git a/build.go b/build.go
index 9e91800..b1a525e 100644
--- a/build.go
+++ b/build.go
@@ -1,12 +1,15 @@
package main
import (
+ "bytes"
_ "embed"
"encoding/json"
+ "flag"
"fmt"
"html/template"
"maps"
"os"
+ "os/exec"
"regexp"
"slices"
"strconv"
@@ -16,6 +19,9 @@ import (
log "github.com/sirupsen/logrus"
)
+const caniuseRepoURL = "https://github.com/jplatte/caniuse.rs"
+const rustRepoURL = "https://github.com/rust-lang/rust"
+
var codeRegex = regexp.MustCompile("`(.+?)`")
//go:embed template.html.tmpl
@@ -27,13 +33,39 @@ var script []byte
//go:embed style.css
var style []byte
+//go:embed find-lib-feats.sh
+var findLibFeatsShellCommand string
+
func main() {
caniuseRepo := "caniuse.rs"
+ rustRepo := "rust"
outDir := "out"
- libFeaturesText, err := os.ReadFile("lib_feats.txt")
+ skipDownload := flag.Bool("skip-download", false,
+ fmt.Sprintf("skip cloning/updating the %s and %s repos", caniuseRepo, rustRepo))
+ flag.Parse()
+
+ if !*skipDownload {
+ if _, err := os.Stat(caniuseRepo); os.IsNotExist(err) {
+ runCommand("git", "clone", caniuseRepoURL, caniuseRepo)
+ } else {
+ runCommand("git", "-C", caniuseRepo, "pull")
+ }
+
+ if _, err := os.Stat(rustRepo); os.IsNotExist(err) {
+ runCommand("git", "clone", rustRepoURL, rustRepo, "--depth", "1")
+ } else {
+ runCommand("git", "-C", rustRepo, "fetch", "--depth", "1")
+ runCommand("git", "-C", rustRepo, "reset", "--hard", "origin/master")
+ }
+ }
+
+ cmd := exec.Command("sh", "-c", findLibFeatsShellCommand, "find-lib-feats.sh", rustRepo)
+ var stderr bytes.Buffer
+ cmd.Stderr = &stderr
+ libFeaturesText, err := cmd.Output()
if err != nil {
- log.Fatalf("error reading lib_feats.txt: %s", err)
+ log.WithField("stderr", stderr.String()).Fatalf("failed to run shell command to find library features: %s", err)
}
libFeatureFlags := strings.Split(string(libFeaturesText), "\n")
@@ -110,7 +142,8 @@ func main() {
err = tmpl.Execute(outputFile,
map[string]any{
- "Versions": versions,
+ "Versions": versions,
+ "CaniuseRepoURL": caniuseRepoURL,
},
)
if err != nil {
@@ -235,6 +268,15 @@ func compareVersion(a, b string) int {
return aMinor - bMinor
}
+func runCommand(name string, args ...string) {
+ cmd := exec.Command(name, args...)
+ var stderr bytes.Buffer
+ cmd.Stderr = &stderr
+ if err := cmd.Run(); err != nil {
+ log.WithField("stderr", stderr.String()).Fatalf("command '%s %v' failed: %v", name, args, err)
+ }
+}
+
// workaround for https://github.com/golang/go/issues/37711
func nilAsEmptyArray[T any](slice []T) []T {
return append([]T{}, slice...)