mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 07:21:32 +08:00
Revert "Added possibility to specify platform for dev command (#3117)"
This reverts commit 4b4fcdd47c
.
This commit is contained in:
parent
772f870eb3
commit
741558532b
@ -108,7 +108,7 @@ func buildApplication(f *flags.Build) error {
|
|||||||
{"Tags", "[" + strings.Join(f.GetTags(), ",") + "]"},
|
{"Tags", "[" + strings.Join(f.GetTags(), ",") + "]"},
|
||||||
{"Race Detector", bool2Str(f.RaceDetector)},
|
{"Race Detector", bool2Str(f.RaceDetector)},
|
||||||
}...)
|
}...)
|
||||||
if len(buildOptions.OutputFile) > 0 && len(f.GetTargets()) == 1 {
|
if len(buildOptions.OutputFile) > 0 && f.GetTargets().Length() == 1 {
|
||||||
tableData = append(tableData, []string{"Output File", f.OutputFilename})
|
tableData = append(tableData, []string{"Output File", f.OutputFilename})
|
||||||
}
|
}
|
||||||
pterm.DefaultSection.Println("Build Options")
|
pterm.DefaultSection.Println("Build Options")
|
||||||
@ -145,11 +145,16 @@ func buildApplication(f *flags.Build) error {
|
|||||||
|
|
||||||
// Allows cancelling the build after the first error. It would be nice if targets.Each would support funcs
|
// Allows cancelling the build after the first error. It would be nice if targets.Each would support funcs
|
||||||
// returning an error.
|
// returning an error.
|
||||||
|
var targetErr error
|
||||||
targets := f.GetTargets()
|
targets := f.GetTargets()
|
||||||
for _, target := range targets {
|
targets.Each(func(platform string) {
|
||||||
if !validPlatformArch.Contains(target.Platform) {
|
if targetErr != nil {
|
||||||
buildOptions.Logger.Println("platform '%s' is not supported - skipping. Supported platforms: %s", target.Platform, validPlatformArch.Join(","))
|
return
|
||||||
continue
|
}
|
||||||
|
|
||||||
|
if !validPlatformArch.Contains(platform) {
|
||||||
|
buildOptions.Logger.Println("platform '%s' is not supported - skipping. Supported platforms: %s", platform, validPlatformArch.Join(","))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
desiredFilename := projectOptions.OutputFilename
|
desiredFilename := projectOptions.OutputFilename
|
||||||
@ -158,13 +163,17 @@ func buildApplication(f *flags.Build) error {
|
|||||||
}
|
}
|
||||||
desiredFilename = strings.TrimSuffix(desiredFilename, ".exe")
|
desiredFilename = strings.TrimSuffix(desiredFilename, ".exe")
|
||||||
|
|
||||||
buildOptions.Platform = target.Platform
|
// Calculate platform and arch
|
||||||
buildOptions.Arch = target.Arch
|
platformSplit := strings.Split(platform, "/")
|
||||||
|
buildOptions.Platform = platformSplit[0]
|
||||||
|
buildOptions.Arch = f.GetDefaultArch()
|
||||||
|
if len(platformSplit) > 1 {
|
||||||
|
buildOptions.Arch = platformSplit[1]
|
||||||
|
}
|
||||||
banner := "Building target: " + buildOptions.Platform + "/" + buildOptions.Arch
|
banner := "Building target: " + buildOptions.Platform + "/" + buildOptions.Arch
|
||||||
pterm.DefaultSection.Println(banner)
|
pterm.DefaultSection.Println(banner)
|
||||||
|
|
||||||
if f.Upx && target.String() == "darwin/universal" {
|
if f.Upx && platform == "darwin/universal" {
|
||||||
pterm.Warning.Println("Warning: compress flag unsupported for universal binaries. Ignoring.")
|
pterm.Warning.Println("Warning: compress flag unsupported for universal binaries. Ignoring.")
|
||||||
f.Upx = false
|
f.Upx = false
|
||||||
}
|
}
|
||||||
@ -173,19 +182,22 @@ func buildApplication(f *flags.Build) error {
|
|||||||
case "linux":
|
case "linux":
|
||||||
if runtime.GOOS != "linux" {
|
if runtime.GOOS != "linux" {
|
||||||
pterm.Warning.Println("Crosscompiling to Linux not currently supported.")
|
pterm.Warning.Println("Crosscompiling to Linux not currently supported.")
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
case "darwin":
|
case "darwin":
|
||||||
if runtime.GOOS != "darwin" {
|
if runtime.GOOS != "darwin" {
|
||||||
pterm.Warning.Println("Crosscompiling to Mac not currently supported.")
|
pterm.Warning.Println("Crosscompiling to Mac not currently supported.")
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if targets.MacTargetsCount() == 2 {
|
macTargets := targets.Filter(func(platform string) bool {
|
||||||
|
return strings.HasPrefix(platform, "darwin")
|
||||||
|
})
|
||||||
|
if macTargets.Length() == 2 {
|
||||||
buildOptions.BundleName = fmt.Sprintf("%s-%s.app", desiredFilename, buildOptions.Arch)
|
buildOptions.BundleName = fmt.Sprintf("%s-%s.app", desiredFilename, buildOptions.Arch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(targets) > 1 {
|
if targets.Length() > 1 {
|
||||||
// target filename
|
// target filename
|
||||||
switch buildOptions.Platform {
|
switch buildOptions.Platform {
|
||||||
case "windows":
|
case "windows":
|
||||||
@ -207,27 +219,32 @@ func buildApplication(f *flags.Build) error {
|
|||||||
pterm.Warning.Println("obfuscated flag overrides skipbindings flag.")
|
pterm.Warning.Println("obfuscated flag overrides skipbindings flag.")
|
||||||
buildOptions.SkipBindings = false
|
buildOptions.SkipBindings = false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if !f.DryRun {
|
if !f.DryRun {
|
||||||
// Start Time
|
// Start Time
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
compiledBinary, err := build.Build(buildOptions)
|
compiledBinary, err := build.Build(buildOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pterm.Error.Println(err.Error())
|
pterm.Error.Println(err.Error())
|
||||||
return err
|
targetErr = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
buildOptions.IgnoreFrontend = true
|
||||||
|
buildOptions.CleanBinDirectory = false
|
||||||
|
|
||||||
|
// Output stats
|
||||||
|
buildOptions.Logger.Println(fmt.Sprintf("Built '%s' in %s.\n", compiledBinary, time.Since(start).Round(time.Millisecond).String()))
|
||||||
|
|
||||||
|
outputBinaries[buildOptions.Platform+"/"+buildOptions.Arch] = compiledBinary
|
||||||
|
} else {
|
||||||
|
pterm.Info.Println("Dry run: skipped build.")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
buildOptions.IgnoreFrontend = true
|
if targetErr != nil {
|
||||||
buildOptions.CleanBinDirectory = false
|
return targetErr
|
||||||
|
|
||||||
// Output stats
|
|
||||||
buildOptions.Logger.Println(fmt.Sprintf("Built '%s' in %s.\n", compiledBinary, time.Since(start).Round(time.Millisecond).String()))
|
|
||||||
|
|
||||||
outputBinaries[buildOptions.Platform+"/"+buildOptions.Arch] = compiledBinary
|
|
||||||
} else {
|
|
||||||
pterm.Info.Println("Dry run: skipped build.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.DryRun {
|
if f.DryRun {
|
||||||
|
@ -2,10 +2,13 @@ package flags
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/leaanthony/slicer"
|
"github.com/leaanthony/slicer"
|
||||||
|
"github.com/wailsapp/wails/v2/internal/system"
|
||||||
"github.com/wailsapp/wails/v2/pkg/commands/build"
|
"github.com/wailsapp/wails/v2/pkg/commands/build"
|
||||||
"github.com/wailsapp/wails/v2/pkg/commands/buildtags"
|
"github.com/wailsapp/wails/v2/pkg/commands/buildtags"
|
||||||
)
|
)
|
||||||
@ -46,15 +49,29 @@ type Build struct {
|
|||||||
compilerPath string
|
compilerPath string
|
||||||
userTags []string
|
userTags []string
|
||||||
wv2rtstrategy string // WebView2 runtime strategy
|
wv2rtstrategy string // WebView2 runtime strategy
|
||||||
|
defaultArch string // Default architecture
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Build) Default() *Build {
|
func (b *Build) Default() *Build {
|
||||||
target := defaultTarget()
|
defaultPlatform := os.Getenv("GOOS")
|
||||||
|
if defaultPlatform == "" {
|
||||||
|
defaultPlatform = runtime.GOOS
|
||||||
|
}
|
||||||
|
defaultArch := os.Getenv("GOARCH")
|
||||||
|
if defaultArch == "" {
|
||||||
|
if system.IsAppleSilicon {
|
||||||
|
defaultArch = "arm64"
|
||||||
|
} else {
|
||||||
|
defaultArch = runtime.GOARCH
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result := &Build{
|
result := &Build{
|
||||||
Platform: target.Platform,
|
Platform: defaultPlatform + "/" + defaultArch,
|
||||||
WebView2: "download",
|
WebView2: "download",
|
||||||
GarbleArgs: "-literals -tiny -seed=random",
|
GarbleArgs: "-literals -tiny -seed=random",
|
||||||
|
|
||||||
|
defaultArch: defaultArch,
|
||||||
}
|
}
|
||||||
result.BuildCommon = result.BuildCommon.Default()
|
result.BuildCommon = result.BuildCommon.Default()
|
||||||
return result
|
return result
|
||||||
@ -71,8 +88,11 @@ func (b *Build) GetWebView2Strategy() string {
|
|||||||
return b.wv2rtstrategy
|
return b.wv2rtstrategy
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Build) GetTargets() TargetsCollection {
|
func (b *Build) GetTargets() *slicer.StringSlicer {
|
||||||
return parseTargets(b.Platform)
|
var targets slicer.StringSlicer
|
||||||
|
targets.AddSlice(strings.Split(b.Platform, ","))
|
||||||
|
targets.Deduplicate()
|
||||||
|
return &targets
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Build) GetCompilerPath() string {
|
func (b *Build) GetCompilerPath() string {
|
||||||
@ -124,6 +144,10 @@ func (b *Build) GetBuildModeAsString() string {
|
|||||||
return "production"
|
return "production"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Build) GetDefaultArch() string {
|
||||||
|
return b.defaultArch
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
_, _ = fmt.Fprintf(w, "Frontend Directory: \t%s\n", projectOptions.GetFrontendDir())
|
_, _ = fmt.Fprintf(w, "Frontend Directory: \t%s\n", projectOptions.GetFrontendDir())
|
||||||
_, _ = fmt.Fprintf(w, "Obfuscated: \t%t\n", buildOptions.Obfuscated)
|
_, _ = fmt.Fprintf(w, "Obfuscated: \t%t\n", buildOptions.Obfuscated)
|
||||||
|
@ -1,103 +1,5 @@
|
|||||||
package flags
|
package flags
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/leaanthony/slicer"
|
|
||||||
"github.com/pterm/pterm"
|
|
||||||
"github.com/wailsapp/wails/v2/internal/system"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Common struct {
|
type Common struct {
|
||||||
NoColour bool `description:"Disable colour in output"`
|
NoColour bool `description:"Disable colour in output"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Target struct {
|
|
||||||
Platform string
|
|
||||||
Arch string
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultTarget() Target {
|
|
||||||
defaultPlatform := os.Getenv("GOOS")
|
|
||||||
if defaultPlatform == "" {
|
|
||||||
defaultPlatform = runtime.GOOS
|
|
||||||
}
|
|
||||||
defaultArch := os.Getenv("GOARCH")
|
|
||||||
if defaultArch == "" {
|
|
||||||
if system.IsAppleSilicon {
|
|
||||||
defaultArch = "arm64"
|
|
||||||
} else {
|
|
||||||
defaultArch = runtime.GOARCH
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Target{
|
|
||||||
Platform: defaultPlatform,
|
|
||||||
Arch: defaultArch,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type TargetsCollection []Target
|
|
||||||
|
|
||||||
func (c TargetsCollection) MacTargetsCount() int {
|
|
||||||
count := 0
|
|
||||||
|
|
||||||
for _, t := range c {
|
|
||||||
if strings.HasPrefix(t.Platform, "darwin") {
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t Target) String() string {
|
|
||||||
if t.Arch != "" {
|
|
||||||
return fmt.Sprintf("%s/%s", t.Platform, t.Arch)
|
|
||||||
}
|
|
||||||
|
|
||||||
return t.Platform
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseTargets(platform string) TargetsCollection {
|
|
||||||
allowedPlatforms := map[string]bool{
|
|
||||||
"windows": true,
|
|
||||||
"linux": true,
|
|
||||||
"darwin": true,
|
|
||||||
}
|
|
||||||
|
|
||||||
if !allowedPlatforms[platform] {
|
|
||||||
pterm.Error.Println("platform argument must be one of 'windows', 'linux', or 'darwin'")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
var result []Target
|
|
||||||
var targets slicer.StringSlicer
|
|
||||||
|
|
||||||
targets.AddSlice(strings.Split(platform, ","))
|
|
||||||
targets.Deduplicate()
|
|
||||||
|
|
||||||
targets.Each(func(platform string) {
|
|
||||||
target := Target{
|
|
||||||
Platform: "",
|
|
||||||
Arch: "",
|
|
||||||
}
|
|
||||||
|
|
||||||
platformSplit := strings.Split(platform, "/")
|
|
||||||
|
|
||||||
target.Platform = platformSplit[0]
|
|
||||||
|
|
||||||
if len(platformSplit) > 1 {
|
|
||||||
target.Arch = platformSplit[1]
|
|
||||||
} else {
|
|
||||||
target.Arch = defaultTarget().Arch
|
|
||||||
}
|
|
||||||
|
|
||||||
result = append(result, target)
|
|
||||||
})
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"github.com/wailsapp/wails/v2/internal/project"
|
"github.com/wailsapp/wails/v2/internal/project"
|
||||||
@ -16,7 +17,6 @@ type Dev struct {
|
|||||||
BuildCommon
|
BuildCommon
|
||||||
|
|
||||||
AssetDir string `flag:"assetdir" description:"Serve assets from the given directory instead of using the provided asset FS"`
|
AssetDir string `flag:"assetdir" description:"Serve assets from the given directory instead of using the provided asset FS"`
|
||||||
Platform string `flag:"platform" description:"Platform to target"`
|
|
||||||
Extensions string `flag:"e" description:"Extensions to trigger rebuilds (comma separated) eg go"`
|
Extensions string `flag:"e" description:"Extensions to trigger rebuilds (comma separated) eg go"`
|
||||||
ReloadDirs string `flag:"reloaddirs" description:"Additional directories to trigger reloads (comma separated)"`
|
ReloadDirs string `flag:"reloaddirs" description:"Additional directories to trigger reloads (comma separated)"`
|
||||||
Browser bool `flag:"browser" description:"Open the application in a browser"`
|
Browser bool `flag:"browser" description:"Open the application in a browser"`
|
||||||
@ -38,13 +38,10 @@ type Dev struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (*Dev) Default() *Dev {
|
func (*Dev) Default() *Dev {
|
||||||
target := defaultTarget()
|
|
||||||
result := &Dev{
|
result := &Dev{
|
||||||
Extensions: "go",
|
Extensions: "go",
|
||||||
Debounce: 100,
|
Debounce: 100,
|
||||||
Platform: target.Platform,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result.BuildCommon = result.BuildCommon.Default()
|
result.BuildCommon = result.BuildCommon.Default()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -119,15 +116,13 @@ func (d *Dev) loadAndMergeProjectConfig() error {
|
|||||||
|
|
||||||
// GenerateBuildOptions creates a build.Options using the flags
|
// GenerateBuildOptions creates a build.Options using the flags
|
||||||
func (d *Dev) GenerateBuildOptions() *build.Options {
|
func (d *Dev) GenerateBuildOptions() *build.Options {
|
||||||
targets := parseTargets(d.Platform)
|
|
||||||
|
|
||||||
result := &build.Options{
|
result := &build.Options{
|
||||||
OutputType: "dev",
|
OutputType: "dev",
|
||||||
Mode: build.Dev,
|
Mode: build.Dev,
|
||||||
Devtools: true,
|
Devtools: true,
|
||||||
Arch: targets[0].Arch,
|
Arch: runtime.GOARCH,
|
||||||
Pack: true,
|
Pack: true,
|
||||||
Platform: targets[0].Platform,
|
Platform: runtime.GOOS,
|
||||||
LDFlags: d.LdFlags,
|
LDFlags: d.LdFlags,
|
||||||
Compiler: d.Compiler,
|
Compiler: d.Compiler,
|
||||||
ForceBuild: d.ForceBuild,
|
ForceBuild: d.ForceBuild,
|
||||||
|
@ -268,16 +268,6 @@ func runFrontendDevWatcherCommand(frontendDirectory string, devCommand string, d
|
|||||||
}, viteServerURL, viteVersion, nil
|
}, viteServerURL, viteVersion, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func isWsl() bool {
|
|
||||||
version, err := os.ReadFile("/proc/version")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.Contains(strings.ToLower(string(version)), "wsl")
|
|
||||||
}
|
|
||||||
|
|
||||||
// restartApp does the actual rebuilding of the application when files change
|
// restartApp does the actual rebuilding of the application when files change
|
||||||
func restartApp(buildOptions *build.Options, debugBinaryProcess *process.Process, f *flags.Dev, exitCodeChannel chan int, legacyUseDevServerInsteadofCustomScheme bool) (*process.Process, string, error) {
|
func restartApp(buildOptions *build.Options, debugBinaryProcess *process.Process, f *flags.Dev, exitCodeChannel chan int, legacyUseDevServerInsteadofCustomScheme bool) (*process.Process, string, error) {
|
||||||
appBinary, err := build.Build(buildOptions)
|
appBinary, err := build.Build(buildOptions)
|
||||||
@ -316,12 +306,6 @@ func restartApp(buildOptions *build.Options, debugBinaryProcess *process.Process
|
|||||||
os.Setenv("devserver", f.DevServer)
|
os.Setenv("devserver", f.DevServer)
|
||||||
os.Setenv("frontenddevserverurl", f.FrontendDevServerURL)
|
os.Setenv("frontenddevserverurl", f.FrontendDevServerURL)
|
||||||
|
|
||||||
if buildOptions.IsWindowsTargetPlatform() && isWsl() {
|
|
||||||
// In the case of building a Windows executable under WSL, we need to specify this variable with a list of
|
|
||||||
// variables that will be passed through
|
|
||||||
os.Setenv("WSLENV", "loglevel/w:frontenddevserverurl/w:devserver/w:assetdir/w")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start up new binary with correct args
|
// Start up new binary with correct args
|
||||||
newProcess := process.NewProcess(appBinary, args...)
|
newProcess := process.NewProcess(appBinary, args...)
|
||||||
err = newProcess.Start(exitCodeChannel)
|
err = newProcess.Start(exitCodeChannel)
|
||||||
|
@ -71,10 +71,6 @@ type Options struct {
|
|||||||
SkipBindings bool // Skip binding generation
|
SkipBindings bool // Skip binding generation
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Options) IsWindowsTargetPlatform() bool {
|
|
||||||
return strings.Contains(strings.ToLower(o.Platform), "windows")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the project!
|
// Build the project!
|
||||||
func Build(options *Options) (string, error) {
|
func Build(options *Options) (string, error) {
|
||||||
// Extract logger
|
// Extract logger
|
||||||
|
@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
## v2.8.0 - 2024-02-08
|
## v2.8.0 - 2024-02-08
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- Added option to specify platform for dev command. Thanks to [@pylotlight](https://github.com/pylotlight) for the fix ([#3117](https://github.com/wailsapp/wails/pull/3117)). Based on the work of [@evsign](https://github.com/evsign) in [Draft PR](https://github.com/wailsapp/wails/pull/2724).
|
|
||||||
- Added windows options supports `DisablePinchZoom` configuration. Added by @tuuzed in [PR](https://github.com/wailsapp/wails/pull/3115)
|
- Added windows options supports `DisablePinchZoom` configuration. Added by @tuuzed in [PR](https://github.com/wailsapp/wails/pull/3115)
|
||||||
- Add Apple Silicon hardware detection to `wails doctor`. Changed by @almas1992 in [PR](https://github.com/wailsapp/wails/pull/3129)
|
- Add Apple Silicon hardware detection to `wails doctor`. Changed by @almas1992 in [PR](https://github.com/wailsapp/wails/pull/3129)
|
||||||
- Remove quarantine attribute on macOS binaries. Changed by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/3118)
|
- Remove quarantine attribute on macOS binaries. Changed by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/3118)
|
||||||
|
Loading…
Reference in New Issue
Block a user