Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: flag validation fails when `pkg-config --libs` reports a path containing spaces #35262

Open
CannibalVox opened this issue Oct 31, 2019 · 2 comments

Comments

@CannibalVox
Copy link

@CannibalVox CannibalVox commented Oct 31, 2019

What version of Go are you using (go version)?

$ go version
go version go1.13.1 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Stephen Baynham\AppData\Local\go-build
set GOENV=C:\Users\Stephen Baynham\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Stephen Baynham\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\Stephen Baynham\source\repos\go-luajit\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\STEPHE~1\AppData\Local\Temp\go-build884938030=/tmp/go-build -gno-record-gcc-switches

What did you do?

Place the -L directory of a C lib into a directory with a space in it, and access it a pkg-config .pc file.

/*
#cgo pkg-config: luajit
#include "go_luajit.h"
*/
import "C"

func main() {}

Attempt to build:

$ pkg-config --cflags luajit
-IC:/Program\ Files/Git/usr/local/include/luajit-2.0

$ pkg-config --libs luajit
-LC:/Program\ Files/Git/usr/local/lib -lluajit-5.1

$ go build ./...
go build github.com/cannibalvox/luajitter: invalid flag in pkg-config --libs: Files/Git/usr/local/lib

What did you expect to see?

Successful build.

What did you see instead?

go build github.com/cannibalvox/luajitter: invalid flag in pkg-config --libs: Files/Git/usr/local/lib

Context

In 2016, this issue was brought up and was successfully solved, but only for CFlags: #16455

Commit: https://go-review.googlesource.com/c/go/+/32735/6/src/cmd/go/build.go

However, on windows where the (git bash) mingw /usr directory is in C:\Program Files, both the include and lib directories have spaces in them. In issue 16455, it was determined to wait on windows until more information was provided. However, the linked commit fixes linux as well as windows. The only problem is that the fix was only applied to CFLAGS and not LDFLAGS. Having LDFLAGS also use splitPkgConfigOutput instead of strings.Fields would solve this problem entirely. Are there any considerations that might prevent me from PRing a straight 1:1 replacement?

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Nov 5, 2019

@bcmills bcmills changed the title Make pkg-config --libs also handle spaces in paths cmd/go: flag validation fails when `pkg-config --libs` reports a path containing spaces Nov 5, 2019
@bcmills bcmills added this to the Backlog milestone Nov 5, 2019
@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Nov 5, 2019

Are there any considerations that might prevent me from PRing a straight 1:1 replacement?

I'm not aware of any. Send a PR (and, ideally, a regression test) and we can discuss on the code review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.