Skip to content

Commit

Permalink
recover ci.go xgo command
Browse files Browse the repository at this point in the history
  • Loading branch information
0xe3b0c4 committed Aug 9, 2022
1 parent 3f8f36b commit 4eeb27a
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Usage: go run build/ci.go <command> <command flags/arguments>
Available commands are:
install [ -arch architecture ] [ -cc compiler ] [ packages... ] -- builds packages and executables
install [ -arch architecture ] [-static] [ -cc compiler ] [ packages... ] -- builds packages and executables
test [ -coverage ] [ packages... ] -- runs the tests
lint -- runs certain pre-selected linters
archive [ -arch architecture ] [ -type zip|tar ] [ -signer key-envvar ] [ -signify key-envvar ] [ -upload dest ] -- archives build artifacts
Expand All @@ -33,6 +33,7 @@ Available commands are:
nsis -- creates a Windows NSIS installer
aar [ -local ] [ -sign key-id ] [-deploy repo] [ -upload dest ] -- creates an Android archive
xcode [ -local ] [ -sign key-id ] [-deploy repo] [ -upload dest ] -- creates an iOS XCode framework
xgo [ -alltools ] [-static] [ options ] -- cross builds according to options
purge [ -store blobstore ] [ -days threshold ] -- purges old archives from the blobstore
For all commands, -n prevents execution of external programs (dry run mode).
Expand Down Expand Up @@ -186,6 +187,8 @@ func main() {
doAndroidArchive(os.Args[2:])
case "xcode":
doXCodeFramework(os.Args[2:])
case "xgo":
doXgo(os.Args[2:])
case "purge":
doPurge(os.Args[2:])
default:
Expand Down Expand Up @@ -1232,6 +1235,52 @@ func newPodMetadata(env build.Environment, archive string) podMetadata {
}
}

// Cross compilation

func doXgo(cmdline []string) {
var (
alltools = flag.Bool("alltools", false, `Flag whether we're building all known tools, or only on in particular`)
staticlink = flag.Bool("static", false, "Static link build with")
)
flag.CommandLine.Parse(cmdline)
env := build.Env()
var tc build.GoToolchain

// Make sure xgo is available for cross compilation
build.MustRun(tc.Install(GOBIN, "github.com/karalabe/xgo@latest"))

// Disable CLI markdown doc generation in release builds.
buildTags := []string{"urfave_cli_no_docs"}

// If all tools building is requested, build everything the builder wants
args := append(buildFlags(env, *staticlink, buildTags), flag.Args()...)

if *alltools {
args = append(args, []string{"--dest", GOBIN}...)
for _, res := range allToolsArchiveFiles {
if strings.HasPrefix(res, GOBIN) {
// Binary tool found, cross build it explicitly
args = append(args, "./"+filepath.Join("cmd", filepath.Base(res)))
build.MustRun(xgoTool(args))
args = args[:len(args)-1]
}
}
return
}

// Otherwise execute the explicit cross compilation
path := args[len(args)-1]
args = append(args[:len(args)-1], []string{"--dest", GOBIN, path}...)
build.MustRun(xgoTool(args))
}

func xgoTool(args []string) *exec.Cmd {
cmd := exec.Command(filepath.Join(GOBIN, "xgo"), args...)
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, []string{"GOBIN=" + GOBIN}...)
return cmd
}

// Binary distribution cleanups

func doPurge(cmdline []string) {
Expand Down

0 comments on commit 4eeb27a

Please sign in to comment.