wails: Cross compilation using xgo does not copy local (unpublished) packages

Description

I’ve been trying to cross compile for windows from my Linux machine and ran into an issue. I have a go module in a different directory than the one in which my wails project is located—I import this module in a go.mod file in my wails project directory using the replace keyword. When I try to compile, I get the following message:

Compiling for windows-4.0/amd64...
go: github.com/username/projectname/client@v0.0.0-00010101000000-000000000000: parsing /home/dk/go/src/github.com/username/projectname/client/go.mod: open /home/dk/go/src/github.com/username/projectname/client/go.mod: no such file or directory

I suspect that the output is from the Docker container, and that the necessary files are not being copied in.

To Reproduce Steps to reproduce the behaviour:

  1. Import a local go module outside the immediate project directory using go modules’ replace keyword from within the go.mod of your wails project directory.
  2. Run wails build -x windows/amd64 --verbose. The error described above should appear.
  3. Wails will claim that the project built successfully, but the build folder will be empty.

Expected behaviour The cross-compilation builds a functioning windows executable.

System Details

Name Value
Wails Version v1.7.1
Go Version go1.14.2
Platform linux
Arch amd64
GO111MODULE (Not Set)
GCC 7.5.0
Npm 6.14.4
Node v12.17.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 25 (19 by maintainers)

Most upvoted comments

@DanielKrolopp Would you mind checking out the feature branch feature/goroot I just pushed up that allows you to specify the -goroot flag and provide the location on your drive of the GOROOT environment value?

Passing that in causes the location on your host to be mounted at /go inside the cross-compiler container. This should enable a replace github.com/wailsapp/wails => github.com/DanielKrolopp/wails style of substitution.

| |     / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__  )  v1.8.0
|__/|__/\__,_/_/_/____/   https://wails.app
The lightweight framework for web-like apps

wails build - Builds your Wails project

This command will check to ensure all pre-requistes are installed prior to building. If not, it will attempt to install them. Building comprises of a number of steps: install frontend dependencies, build frontend, pack frontend, compile main application.

Flags:

  -d	Build in Debug mode
  -f	Force rebuild of application components
  -goroot string
    	Specify your goroot location. Mounted to /go during cross-compilation.
  -help
    	Get help on the 'wails build' command.
  -ldflags string
    	Extra options for -ldflags
  -p	Package application on successful build
  -t string
    	Generate Typescript definitions to given file (at runtime)
  -verbose
    	Verbose output
  -x string
    	Cross-compile application to specified platform via xgo
    	 - darwin/amd64
    	 - linux/amd64
    	 - linux/arm-7
    	 - windows/amd64

Example:

wails build -x windows/amd64 -goroot ~/go

Was this solved? Do we need to merge in the fixes on the branch?

It was merged to develop. I don’t know if we have cut a release yet containing it.

I think I have a solution for this. Please bear with us 😃

Another user reported this on slack: using replace in go.mod will also fail cross-compile:

// go.mod
require (
  ...
  ...
  github.com/Me/myproject v0.1.0
)
replace github.com/Me/myproject => ../myproject