golang cross compilation on mac for windows - windows

I am writing a go program to parse csv files and upload them to a postgres database in the Heroku cloud. The program works fine on my mac laptop. Eventual target platform for deploying the code is Windows though. I did some research and found that the following command creates a Windows executable on my Mac.
env GOOS=windows GOARCH=386 go build -v main.go
This produced an executable called main.exe when I had just one file called main.go. The program has grown since then and I have it now split into three source files:
main.go
common.go
specific.go
They are all in the same source directory though. Moreover, since the program is relatively small, I have all functions in the 'main' package. What is the command now to cross-compile on mac for windows for multiple source files belonging to the same package? The previous command did not work since the other two file common.go and specific.go are not included. Also, I would like to know how to rename the Windows 'exe' file to something else than main.exe, e.g., upload.exe? I am using go version go1.5 darwin/amd64

Related

How to distribute Chromium binary after compiling? Directory has over 39GB

I want to distribute Chromium I just compiled. The problem is, just after compiling, the directory with the binary weights over 39GB!
How can I filter only needed for operation files? I think it should be at most about 1GB.
I am on Windows, and followed instructions from here: https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md
The directory in question looks like this: several subdirectories, and ~1400 single files in root.
Ideally I'm looking for specific guidline, including files and folders I must keep.
You have to distribute mini installer only which will be in your build folder as mini_installer.exe. You can build mini installer by executing the following command:
ninja -C out\YourBuildFolder mini_installer
Basically mini installer is just a packer which packs the following files:
setup.exe
chrome.packed.7z
More information on it can be found here. So executing mini installer will extract those files and execute setup.exe, which will then install your Chromium fork. Also, for distributing your fork, you should build release versions which you can specify when you run this command:
gn args out\YourBuildFolder
Basically it will open args.gn file located in out\YourBuildFolder and then you set:
is_debug = false
You might need those files and folders for debugging your Chromium fork as it includes the debug symbols, which are required for debugging.

Can we make solution file from cmake in one machine and run in another?

I have written a build system in cmake that works in linux and windows. In windows I generate solution file using cmake and use that solution file to build my project. The current solution file (generated by cmake) looks like it can only run from my machine. So I was wondering is there any way in cmake that can generate solution file in one machine and run in another.

How to distribute gcc compiler binaries?

I want to distribute a gcc compiler within our company. I built required version from the sources, installed it in specified directory on my machine (all machines, btw, have the same architecture). I expected that I can put contents of this directory on the server and with the next update all my colleagues will get a new compiler.
But of course that doesn't work.
I tried to search for a ready solution for the linux but couldn't find anything.
Right now if I try to compile some basic program I get an error:
gcc: error trying to exec 'cc1plus': execvp: No such file or directory.
But this file was build and indeed resides in one of the subfolders of main install directory. I tried to explicitly specify the path to this subprogramm using GCC_EXEC_PREFIX and COMPILER_PATH environment variables but with no luck.
Is it possible to achieve what I want?

How do you share your GOPATH via Dropbox (or similar) across multiple platforms

I develop across 3 different platforms, Windows, OS X and Ubuntu Linux.
I use Dropbox to synchronize my code between all 3 platforms.
The problem I have is compiled binaries on OS X and Linux get the same name, so binaries in my GOPATH are always overwriting each other. I don't have this problem with Windows because binaries always compile with a .exe extension.
Has anyone else experienced this problem, and if so, how did you get around it?
The solution is simple: only share the $GOPATH/src folder across your computers, there is really no need to share the complete $GOPATH as package objects ($GOPATH/pkg) and binaries ($GOPATH/bin) compiled to one platform have no real use on other platforms, and they are reproducible by a simple compilation.
This will also reduce the storage and bandwidth. If for some reason you would still need the compiled binaries for other platforms, the go tool has built-in support for cross compilation, e.g. GOOS=windows go build will simply produce you the Windows executable binary of the package whose folder you're in in any OS, placed in the current folder (you can also change the architecture with GOARCH).
Another option would be to put your code under a source control e.g. git (github.com), which also preserves history. The go tool also has support to easily get the source code from a git repository, e.g. go get -u github.com/youruser/yourpackage.
1- set GOBIN to separate path (just e.g. for OS X) and use
go install
Command go :
If the GOBIN environment variable is set, commands are installed to the
directory it names instead of DIR/bin. GOBIN must be an absolute path.
2- Also you may rename the output file:
go build [-o output] [-i] [build flags] [packages]
Like this:
go build -o newname
The -o flag, only allowed when compiling a single package, forces
build to write the resulting executable or object to the named output
file.
Also see: How do I use a Samba server location for GOPATH?

Setting GOOS with go run

I'm currently developing a service that can be built as windows service or run as OSX/linux executable.
I'm using build tags on windows files, including the one with a main method
// +build windows
And on the other file containing a main method
// +build !windows
When I execute go run *.go on the mac side, I get the following error
mainDOS.go:10:2: no buildable Go source files in /Users/michaelbrandenburg/Documents/git-repo/goCode/src/golang.org/x/sys/windows/svc
windowsService.go:15:2: no buildable Go source files in /Users/michaelbrandenburg/Documents/git-repo/goCode/src/golang.org/x/sys/windows/svc/debug
install.go:14:2: no buildable Go source files in /Users/michaelbrandenburg/Documents/git-repo/goCode/src/golang.org/x/sys/windows/svc/eventlog
install.go:15:2: no buildable Go source files in /Users/michaelbrandenburg/Documents/git-repo/goCode/src/golang.org/x/sys/windows/svc/mgr
Is there a way to run go run and target the architecture I want to run? I can build the executables with no problem.
GOOS=darwin go run *.go will set the env for Mac OSX. Though, like JimB said, there isn't much of a point. Doing GOOS=darwin go build *.go is a good way to cross compile though

Resources