mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 22:55:48 +01:00
Compare commits
1 commit
master
...
feature/cc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c24aef8ea1 |
5 changed files with 1510 additions and 31 deletions
|
|
@ -264,11 +264,6 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch buildOptions.Platform {
|
switch buildOptions.Platform {
|
||||||
case "linux":
|
|
||||||
if runtime.GOOS != "linux" {
|
|
||||||
logger.Println("Crosscompiling to Linux not currently supported.\n")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case "darwin":
|
case "darwin":
|
||||||
if runtime.GOOS != "darwin" {
|
if runtime.GOOS != "darwin" {
|
||||||
logger.Println("Crosscompiling to Mac not currently supported.\n")
|
logger.Println("Crosscompiling to Mac not currently supported.\n")
|
||||||
|
|
|
||||||
36
v2/go.mod
36
v2/go.mod
|
|
@ -7,15 +7,15 @@ require (
|
||||||
github.com/fatih/structtag v1.2.0
|
github.com/fatih/structtag v1.2.0
|
||||||
github.com/flytam/filenamify v1.0.0
|
github.com/flytam/filenamify v1.0.0
|
||||||
github.com/fsnotify/fsnotify v1.4.9
|
github.com/fsnotify/fsnotify v1.4.9
|
||||||
|
github.com/fsouza/go-dockerclient v1.7.8
|
||||||
github.com/gabriel-vasile/mimetype v1.3.1
|
github.com/gabriel-vasile/mimetype v1.3.1
|
||||||
github.com/go-git/go-billy/v5 v5.2.0 // indirect
|
github.com/go-git/go-billy/v5 v5.2.0 // indirect
|
||||||
github.com/go-git/go-git/v5 v5.3.0
|
github.com/go-git/go-git/v5 v5.3.0
|
||||||
github.com/gofiber/fiber/v2 v2.17.0
|
github.com/gofiber/fiber/v2 v2.17.0
|
||||||
github.com/gofiber/websocket/v2 v2.0.8
|
github.com/gofiber/websocket/v2 v2.0.8
|
||||||
github.com/golang/protobuf v1.5.2 // indirect
|
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||||
github.com/google/uuid v1.1.2 // indirect
|
github.com/google/uuid v1.2.0 // indirect
|
||||||
github.com/gorilla/websocket v1.4.1
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/imdario/mergo v0.3.12
|
github.com/imdario/mergo v0.3.12
|
||||||
github.com/jackmordaunt/icns v1.0.0
|
github.com/jackmordaunt/icns v1.0.0
|
||||||
github.com/leaanthony/clir v1.0.4
|
github.com/leaanthony/clir v1.0.4
|
||||||
|
|
@ -40,21 +40,29 @@ require (
|
||||||
github.com/tidwall/sjson v1.1.7
|
github.com/tidwall/sjson v1.1.7
|
||||||
github.com/wzshiming/ctc v1.2.3
|
github.com/wzshiming/ctc v1.2.3
|
||||||
github.com/ztrue/tracerr v0.3.0
|
github.com/ztrue/tracerr v0.3.0
|
||||||
golang.org/x/mod v0.4.1
|
golang.org/x/mod v0.4.2
|
||||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed
|
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f
|
||||||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9
|
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9
|
||||||
golang.org/x/tools v0.1.0
|
golang.org/x/tools v0.1.5
|
||||||
nhooyr.io/websocket v1.8.6
|
nhooyr.io/websocket v1.8.6
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Microsoft/go-winio v0.4.16 // indirect
|
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
|
||||||
|
github.com/Microsoft/go-winio v0.5.1 // indirect
|
||||||
|
github.com/Microsoft/hcsshim v0.9.2 // indirect
|
||||||
github.com/andybalholm/brotli v1.0.2 // indirect
|
github.com/andybalholm/brotli v1.0.2 // indirect
|
||||||
|
github.com/containerd/cgroups v1.0.3 // indirect
|
||||||
|
github.com/containerd/containerd v1.6.0 // indirect
|
||||||
|
github.com/docker/docker v20.10.12+incompatible // indirect
|
||||||
|
github.com/docker/go-connections v0.4.0 // indirect
|
||||||
|
github.com/docker/go-units v0.4.0 // indirect
|
||||||
github.com/emirpasic/gods v1.12.0 // indirect
|
github.com/emirpasic/gods v1.12.0 // indirect
|
||||||
github.com/fasthttp/websocket v0.0.0-20200320073529-1554a54587ab // indirect
|
github.com/fasthttp/websocket v0.0.0-20200320073529-1554a54587ab // indirect
|
||||||
github.com/go-git/gcfg v1.5.0 // indirect
|
github.com/go-git/gcfg v1.5.0 // indirect
|
||||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||||
github.com/google/go-cmp v0.5.5 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||||
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
|
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
|
||||||
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
|
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
|
||||||
|
|
@ -63,9 +71,17 @@ require (
|
||||||
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e // indirect
|
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.7 // indirect
|
github.com/mattn/go-runewidth v0.0.7 // indirect
|
||||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||||
|
github.com/moby/sys/mount v0.2.0 // indirect
|
||||||
|
github.com/moby/sys/mountinfo v0.5.0 // indirect
|
||||||
|
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
|
||||||
|
github.com/morikuni/aec v1.0.0 // indirect
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
|
||||||
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
|
github.com/opencontainers/image-spec v1.0.2 // indirect
|
||||||
|
github.com/opencontainers/runc v1.1.0 // indirect
|
||||||
github.com/savsgio/gotils v0.0.0-20200117113501-90175b0fbe3f // indirect
|
github.com/savsgio/gotils v0.0.0-20200117113501-90175b0fbe3f // indirect
|
||||||
github.com/sergi/go-diff v1.1.0 // indirect
|
github.com/sergi/go-diff v1.1.0 // indirect
|
||||||
|
github.com/sirupsen/logrus v1.8.1 // indirect
|
||||||
github.com/tidwall/gjson v1.8.0 // indirect
|
github.com/tidwall/gjson v1.8.0 // indirect
|
||||||
github.com/tidwall/match v1.0.3 // indirect
|
github.com/tidwall/match v1.0.3 // indirect
|
||||||
github.com/tidwall/pretty v1.1.0 // indirect
|
github.com/tidwall/pretty v1.1.0 // indirect
|
||||||
|
|
@ -75,8 +91,10 @@ require (
|
||||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||||
github.com/wzshiming/winseq v0.0.0-20200112104235-db357dc107ae // indirect
|
github.com/wzshiming/winseq v0.0.0-20200112104235-db357dc107ae // indirect
|
||||||
github.com/xanzy/ssh-agent v0.3.0 // indirect
|
github.com/xanzy/ssh-agent v0.3.0 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
|
go.opencensus.io v0.23.0 // indirect
|
||||||
|
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
|
||||||
golang.org/x/image v0.0.0-20201208152932-35266b937fa6 // indirect
|
golang.org/x/image v0.0.0-20201208152932-35266b937fa6 // indirect
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||||
gopkg.in/warnings.v0 v0.1.2 // indirect
|
gopkg.in/warnings.v0 v0.1.2 // indirect
|
||||||
|
gotest.tools/v3 v3.1.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
||||||
148
v2/internal/docker/docker.go
Normal file
148
v2/internal/docker/docker.go
Normal file
|
|
@ -0,0 +1,148 @@
|
||||||
|
package docker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
dc "github.com/fsouza/go-dockerclient"
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CrossCompile(projectPath string, outputfilename string, platform string, verbose bool, loggerWriter io.Writer) error {
|
||||||
|
|
||||||
|
client, err := dc.NewClientFromEnv()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
tag := strings.ReplaceAll(platform, "/", "-")
|
||||||
|
|
||||||
|
outputStream := io.Discard
|
||||||
|
if verbose {
|
||||||
|
outputStream = loggerWriter
|
||||||
|
}
|
||||||
|
|
||||||
|
err = client.PullImage(dc.PullImageOptions{
|
||||||
|
All: false,
|
||||||
|
Repository: "wailsapp/cc",
|
||||||
|
Tag: tag,
|
||||||
|
Platform: "",
|
||||||
|
Registry: "",
|
||||||
|
OutputStream: outputStream,
|
||||||
|
RawJSONStream: false,
|
||||||
|
InactivityTimeout: 0,
|
||||||
|
Context: context.Background(),
|
||||||
|
}, dc.AuthConfiguration{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
projectDir := projectPath + ":/usr/src/myapp:rw"
|
||||||
|
env := []string{"CGO_ENABLED=1"}
|
||||||
|
if platform == "linux/arm64" {
|
||||||
|
env = append(env, "CC_FOR_TARGET=aarch64-linux-gnu-gcc", "PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig")
|
||||||
|
}
|
||||||
|
|
||||||
|
container, err := client.CreateContainer(dc.CreateContainerOptions{
|
||||||
|
//Name: "wails-" + tag + "-builder",
|
||||||
|
Config: &dc.Config{
|
||||||
|
Env: env,
|
||||||
|
Cmd: []string{"go", "build", "-x", "-tags", "desktop,production", "-o", "build/bin/" + outputfilename},
|
||||||
|
Image: "wailsapp/cc:" + tag,
|
||||||
|
WorkingDir: "/usr/src/myapp",
|
||||||
|
AttachStdin: false,
|
||||||
|
AttachStdout: verbose,
|
||||||
|
AttachStderr: verbose,
|
||||||
|
ArgsEscaped: false,
|
||||||
|
},
|
||||||
|
HostConfig: &dc.HostConfig{
|
||||||
|
Binds: []string{projectDir},
|
||||||
|
Privileged: true,
|
||||||
|
AutoRemove: false,
|
||||||
|
},
|
||||||
|
NetworkingConfig: nil,
|
||||||
|
Context: nil,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = client.StartContainer(container.ID, &dc.HostConfig{
|
||||||
|
Privileged: true,
|
||||||
|
AutoRemove: false,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
statusCode, err := client.WaitContainer(container.ID)
|
||||||
|
if statusCode != 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
client, err := client.NewClientWithOpts(client.FromEnv)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error from Docker1: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
pulloutput, err := client.ImagePull(ctx, image, types.ImagePullOptions{})
|
||||||
|
defer pulloutput.Close()
|
||||||
|
output := loggerWriter
|
||||||
|
if output == nil {
|
||||||
|
output = os.Stdout
|
||||||
|
}
|
||||||
|
_, _ = io.Copy(output, pulloutput)
|
||||||
|
//if err != nil {
|
||||||
|
// if verbose {
|
||||||
|
// println("here")
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// return fmt.Errorf("error from Docker2: %v", err)
|
||||||
|
//}
|
||||||
|
resp, err := client.ContainerCreate(ctx, &container.Config{
|
||||||
|
AttachStdout: verbose,
|
||||||
|
AttachStderr: verbose,
|
||||||
|
Image: image,
|
||||||
|
Env: []string{"CGO_ENABLED=1"},
|
||||||
|
Cmd: []string{"go", "build", "-tags", "desktop,production"},
|
||||||
|
}, &container.HostConfig{
|
||||||
|
Mounts: []mount.Mount{
|
||||||
|
{
|
||||||
|
Type: mount.TypeBind,
|
||||||
|
Source: projectPath,
|
||||||
|
Target: "/usr/src/myapp",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, nil, nil, "")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error from Docker3: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error from Docker4: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
statusCh, errCh := client.ContainerWait(ctx, resp.ID, container.WaitConditionNotRunning)
|
||||||
|
select {
|
||||||
|
case err := <-errCh:
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error from Docker5: %v", err)
|
||||||
|
}
|
||||||
|
case <-statusCh:
|
||||||
|
}
|
||||||
|
|
||||||
|
if verbose {
|
||||||
|
out, err := client.ContainerLogs(ctx, resp.ID, types.ContainerLogsOptions{ShowStdout: true})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error from Docke6r: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = stdcopy.StdCopy(os.Stdout, os.Stderr, out)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/wailsapp/wails/v2/internal/docker"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -186,7 +187,13 @@ func Build(options *Options) (string, error) {
|
||||||
projectData.OutputFilename = outputFile
|
projectData.OutputFilename = outputFile
|
||||||
options.CompiledBinary = filepath.Join(options.BuildDirectory, outputFile)
|
options.CompiledBinary = filepath.Join(options.BuildDirectory, outputFile)
|
||||||
} else {
|
} else {
|
||||||
err = builder.CompileProject(options)
|
if options.Platform == "linux" && runtime.GOOS != "linux" {
|
||||||
|
outputFile := fmt.Sprintf("%s-linux-%s", options.OutputFile, options.Arch)
|
||||||
|
err = docker.CrossCompile(options.ProjectData.Path, outputFile, options.Platform+"/"+options.Arch, options.Verbosity == VERBOSE, options.Logger.Writer)
|
||||||
|
options.CompiledBinary = filepath.Join(options.BuildDirectory, outputFile)
|
||||||
|
} else {
|
||||||
|
err = builder.CompileProject(options)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue