From 4b35233293bfe474c1ca728f0cfa9d66887f25a2 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Fri, 5 Mar 2021 00:13:11 -0800 Subject: [PATCH] Add more archs to s2sx (#333) * Add more archs to s2sx * Compress the internal images. * Move packages to bottom. --- .gitignore | 2 +- .goreleaser.yml | 2 +- s2/README.md | 10 ++++++++-- s2/cmd/_s2sx/gensfx.cmd | 25 +++++++++++++++++++++++++ s2/cmd/_s2sx/gensfx.sh | 16 ++++++++++++++++ s2/cmd/_s2sx/go.mod | 2 +- s2/cmd/_s2sx/main.go | 11 ++++++++--- 7 files changed, 60 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index fd433aa533..b35f8449bf 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,4 @@ _testmain.go *.exe *.test *.prof -/s2/cmd/_sfx/sfx-exe +/s2/cmd/_s2sx/sfx-exe diff --git a/.goreleaser.yml b/.goreleaser.yml index c3c984bfbd..51d0c66161 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -114,7 +114,7 @@ changelog: nfpms: - - file_name_template: "s2-Install_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + file_name_template: "s2_package_{{ .Version }}_{{ .Os }}_{{ .Arch }}" vendor: Klaus Post homepage: https://github.com/klauspost/compress maintainer: Klaus Post diff --git a/s2/README.md b/s2/README.md index a65a109ee2..05b265acba 100644 --- a/s2/README.md +++ b/s2/README.md @@ -247,13 +247,19 @@ Options: Do not overwrite output files -untar Untar on destination +``` Available platforms are: * darwin-amd64 + * darwin-arm64 * linux-amd64 - * windows-amd64 -``` + * linux-arm + * linux-arm64 + * linux-mips64 + * linux-ppc64le + * windows-386 + * windows-amd64 ### Self-extracting TAR files diff --git a/s2/cmd/_s2sx/gensfx.cmd b/s2/cmd/_s2sx/gensfx.cmd index 23efa499d8..ea9ba26ec7 100644 --- a/s2/cmd/_s2sx/gensfx.cmd +++ b/s2/cmd/_s2sx/gensfx.cmd @@ -1,7 +1,32 @@ +go build ../s2c + +DEL /Q sfx-exe\* + SET GOOS=linux SET GOARCH=amd64 go build -ldflags="-s -w" -o ./sfx-exe/%GOOS%-%GOARCH% ./_unpack/main.go +SET GOARCH=arm64 +go build -ldflags="-s -w" -o ./sfx-exe/%GOOS%-%GOARCH% ./_unpack/main.go +SET GOARCH=arm +go build -ldflags="-s -w" -o ./sfx-exe/%GOOS%-%GOARCH% ./_unpack/main.go +SET GOARCH=ppc64le +go build -ldflags="-s -w" -o ./sfx-exe/%GOOS%-%GOARCH% ./_unpack/main.go +SET GOARCH=mips64 +go build -ldflags="-s -w" -o ./sfx-exe/%GOOS%-%GOARCH% ./_unpack/main.go + + SET GOOS=darwin +SET GOARCH=amd64 go build -ldflags="-s -w" -o ./sfx-exe/%GOOS%-%GOARCH% ./_unpack/main.go +SET GOARCH=arm64 +go build -ldflags="-s -w" -o ./sfx-exe/%GOOS%-%GOARCH% ./_unpack/main.go + SET GOOS=windows +SET GOARCH=amd64 +go build -ldflags="-s -w" -o ./sfx-exe/%GOOS%-%GOARCH% ./_unpack/main.go +SET GOARCH=386 go build -ldflags="-s -w" -o ./sfx-exe/%GOOS%-%GOARCH% ./_unpack/main.go + +s2c.exe -rm -slower sfx-exe\* +DEL /Q s2c.exe + diff --git a/s2/cmd/_s2sx/gensfx.sh b/s2/cmd/_s2sx/gensfx.sh index 391435f6df..4938e21d54 100755 --- a/s2/cmd/_s2sx/gensfx.sh +++ b/s2/cmd/_s2sx/gensfx.sh @@ -1,5 +1,21 @@ #!/bin/sh +go build -o=s2c ../s2c + +rm -rf sfx-exe/ || true + GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ./sfx-exe/$GOOS-$GOARCH ./_unpack/main.go +GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o ./sfx-exe/$GOOS-$GOARCH ./_unpack/main.go +GOOS=linux GOARCH=arm go build -ldflags="-s -w" -o ./sfx-exe/$GOOS-$GOARCH ./_unpack/main.go +GOOS=linux GOARCH=ppc64le go build -ldflags="-s -w" -o ./sfx-exe/$GOOS-$GOARCH ./_unpack/main.go +GOOS=linux GOARCH=mpis64 go build -ldflags="-s -w" -o ./sfx-exe/$GOOS-$GOARCH ./_unpack/main.go + GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o ./sfx-exe/$GOOS-$GOARCH ./_unpack/main.go +GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o ./sfx-exe/$GOOS-$GOARCH ./_unpack/main.go + GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o ./sfx-exe/$GOOS-$GOARCH ./_unpack/main.go +GOOS=windows GOARCH=386 go build -ldflags="-s -w" -o ./sfx-exe/$GOOS-$GOARCH ./_unpack/main.go + +./s2c -rm -slower sfx-exe/* + +rm s2c diff --git a/s2/cmd/_s2sx/go.mod b/s2/cmd/_s2sx/go.mod index 8344921606..9fb139bde3 100644 --- a/s2/cmd/_s2sx/go.mod +++ b/s2/cmd/_s2sx/go.mod @@ -1,4 +1,4 @@ -module github.com/klauspost/compress/s2/cmd/_s2sx +module github.com/klauspost/compress/s2/cmd/s2sx go 1.16 diff --git a/s2/cmd/_s2sx/main.go b/s2/cmd/_s2sx/main.go index eca3d9f579..a248ed502f 100644 --- a/s2/cmd/_s2sx/main.go +++ b/s2/cmd/_s2sx/main.go @@ -2,11 +2,13 @@ package main import ( "bufio" + "bytes" "embed" "errors" "flag" "fmt" "io" + "io/ioutil" "os" "path" "path/filepath" @@ -66,7 +68,7 @@ Options:`) exitErr(err) _, _ = fmt.Fprintf(os.Stderr, "\nAvailable platforms are:\n\n") for _, d := range dir { - _, _ = fmt.Fprintf(os.Stderr, " * %s\n", d.Name()) + _, _ = fmt.Fprintf(os.Stderr, " * %s\n", strings.TrimSuffix(d.Name(), ".s2")) } os.Exit(0) @@ -84,17 +86,20 @@ Options:`) files = append(files, found...) } wantPlat := *goos + "-" + *goarch - exec, err := embeddedFiles.ReadFile(path.Join("sfx-exe", wantPlat)) + exec, err := embeddedFiles.ReadFile(path.Join("sfx-exe", wantPlat+".s2")) if os.IsNotExist(err) { dir, err := embeddedFiles.ReadDir("sfx-exe") exitErr(err) _, _ = fmt.Fprintf(os.Stderr, "os-arch %v not available. Available sfx platforms are:\n\n", wantPlat) for _, d := range dir { - _, _ = fmt.Fprintf(os.Stderr, "* %s\n", d.Name()) + _, _ = fmt.Fprintf(os.Stderr, "* %s\n", strings.TrimSuffix(d.Name(), ".s2")) } _, _ = fmt.Fprintf(os.Stderr, "\nUse -os and -arch to specify the destination platform.") os.Exit(1) } + exec, err = ioutil.ReadAll(s2.NewReader(bytes.NewBuffer(exec))) + exitErr(err) + mode := byte(opUnpack) if *untar { mode = opUnTar