Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang - change build working path on Windows

I'm testing simple Go program on Windows 8 with SublimeText3 (GoSublime plugin)

go run -v example.go

and before run it's being compiled inside ..AppData\Local\Temp.. directory. My antivirus program thinks that it's a virus and blocks it:

fork/exec C:\Users\D24F7~1.KAP\AppData\Local\Temp\go-build333212398\command-line-arguments_obj\exe\example.exe: Access is denied.

I can't disable it and my solution is to change the folder where it's being compiled. How can I do that?

like image 601
Dmitry Kapsamun Avatar asked Aug 05 '16 06:08

Dmitry Kapsamun


3 Answers

I change ouput directory

go build -i -o D:\Users\MyProj\out\

-o flag

and put to antivirus ignoring D:\Users\MyProj\out\ directory

like image 195
Vetos Avatar answered Oct 11 '22 06:10

Vetos


The WORK directory (seen if building or running with the -x flag) is taken from the TMP environment variable. Updating that variable through the system properties will change the working directory.

like image 45
Andrey Kaipov Avatar answered Oct 11 '22 08:10

Andrey Kaipov


The GOTMPDIR environment var can be used to control the work directory. This is usually preferable to modifying the system-wide temporary directory. GOTMPDIR was introduced in go 1.10.

Before

> go run -work .\example.go
WORK=C:\Users\MyUserName\AppData\Local\Temp\go-build1002945170
...

Modify permanently in the System Properties > Environment Variables window or temporarily in the shell

# powershell
$env:GOTMPDIR = "C:\Users\MyUserName\MyGoBuilds"

After

> go run -work .\example.go
WORK=C:\Users\MyUserName\MyGoBuilds\go-build1381354702
...

Then you can make the needed antivirus or other security exceptions on the GOTMPDIR directory.

like image 1
dodgio Avatar answered Oct 11 '22 08:10

dodgio