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: errors when using pkg-config 0.29.2 from the OpenWRT toolchain #27940

Closed
corny opened this issue Sep 29, 2018 · 5 comments
Closed

cmd/go: errors when using pkg-config 0.29.2 from the OpenWRT toolchain #27940

corny opened this issue Sep 29, 2018 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@corny
Copy link

corny commented Sep 29, 2018

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

1.10

Does this issue reproduce with the latest release?

not tried, but relevant code has not been changed since 1.10

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

linux / amd64

What did you do?

I tried to build a binary using the library https://github.com/digineo/fastd/fastd with the OpenWRT toolchain.

What did you expect to see?

A successful build.
pkg-config --cflags -- libuecc on the host machine with version 0.29.1-0ubuntu2 prints -I/usr/include/libuecc-7

What did you see instead?

~/workspace/lede/staging_dir/host/bin/pkg-config --cflags -- libuecc
# ~/workspace/lede/staging_dir/host/bin/pkg-config --cflags libuecc
Package -- was not found in the pkg-config search path.
Perhaps you should add the directory containing `--.pc'
to the PKG_CONFIG_PATH environment variable
No package '--' found

pkg-config --cflags -- libuecc in the OpenWRT build environment with pkg-config 0.29.2 fails with Package -- was not found in the pkg-config search path

Possible solution

Remove the "--" argument in src/cmd/go/internal/work/exec.go:

out, err = b.runOut(p.Dir, nil, b.PkgconfigCmd(), "--cflags", pcflags, "--", pkgs)
@mvdan
Copy link
Member

mvdan commented Sep 30, 2018

It's very common for programs to understand -- as the end of the flag arguments. This way, even if any of the strings in pkgs started with a dash, it would still be understood as a regular argument and not a flag.

Locally, I have pkg-config from pkgconf, and it seems to understand -- just fine:

$ pkg-config --version
1.5.3
$ pkg-config --cflags -- libuecc
Package libuecc was not found in the pkg-config search path.
Perhaps you should add the directory containing `libuecc.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libuecc', required by 'virtual:world', not found

I downloaded pkg-config 0.29.2 from freedesktop (https://pkgconfig.freedesktop.org/releases/) and compiled it, but it seems to also understand that flag:

$ ./pkg-config --version
0.29.2
$ ./pkg-config --cflags -- libuecc
Package libuecc was not found in the pkg-config search path.
Perhaps you should add the directory containing `libuecc.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libuecc' found

What am I missing? Does OpenWRT compile pkg-config in some special way that I'm not? Or perhaps I tested the wrong software?

Ideally we wouldn't remove the -- argument, as it's useful and there's (in theory) nothing wrong with using it.

@mvdan mvdan added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 30, 2018
@mvdan mvdan changed the title pkg-config fails in version 0.29.2 cmd/go: errors when using pkg-config 0.29.2 from the OpenWRT toolchain Sep 30, 2018
@mvdan
Copy link
Member

mvdan commented Sep 30, 2018

/cc @bcmills @ianlancetaylor

@corny
Copy link
Author

corny commented Sep 30, 2018

@mvdan Thanks a lot for your investigation. I am going to ask the OpenWRT developers for taking a look at this issue.

Where exactly is the -- argument of pkg-config documented? I can't find anything in the man page.

@mvdan
Copy link
Member

mvdan commented Sep 30, 2018

It seems like pkg-config 0.29.2 uses g_option_context_parse, which has support for --.

You can see the code in question in glib/glib/goption.c:1825, as extracted from the 0.29.2 source:

/* '--' terminates list of arguments */
if (*arg == 0)
  {
    separator_pos = i;
    stop_parsing = TRUE;
    continue;
  }

It's true that the manpage doesn't explicitly mention support for --, but given that it accepts GNU style flags, I'd imagine it's a given that one can stop flag parsing as usual.

Here seems to be OpenWRT's Makefile for pkg-config, though I don't see anything that could change this behavior: https://github.com/openwrt/openwrt/blob/master/tools/pkg-config/Makefile

They do build their own glib though, so perhaps they build it in a specific way that affects flag parsing.

@corny
Copy link
Author

corny commented Oct 1, 2018

This problem has to be fixed in the OpenWRT toolchain.

@corny corny closed this as completed Oct 1, 2018
jow- pushed a commit to lede-project/source that referenced this issue Oct 20, 2018
Go for openwrt passes pkg-config arguments in the format of

        pkg-config --cflags -- pkg-name

which in turn will be passed down to the real pkg-config as something
like

        pkg-config.real --cflags -- pkg-name --define...

and causes the real pkg-config implementation to missinterpret the given
argument list.

This also helps to fix golang/go#27940

Signed-off-by: Arthur Skowronek <arthur.skowronek@tuta.io>
jollaman999 pushed a commit to jollaman999/openwrt that referenced this issue Oct 20, 2018
Go for openwrt passes pkg-config arguments in the format of

        pkg-config --cflags -- pkg-name

which in turn will be passed down to the real pkg-config as something
like

        pkg-config.real --cflags -- pkg-name --define...

and causes the real pkg-config implementation to missinterpret the given
argument list.

This also helps to fix golang/go#27940

Signed-off-by: Arthur Skowronek <arthur.skowronek@tuta.io>
jow- pushed a commit to openwrt/openwrt that referenced this issue Apr 24, 2019
Go for openwrt passes pkg-config arguments in the format of

        pkg-config --cflags -- pkg-name

which in turn will be passed down to the real pkg-config as something
like

        pkg-config.real --cflags -- pkg-name --define...

and causes the real pkg-config implementation to missinterpret the given
argument list.

This also helps to fix golang/go#27940

Signed-off-by: Arthur Skowronek <arthur.skowronek@tuta.io>
(cherry picked from commit 5f2cb6d)
@golang golang locked and limited conversation to collaborators Oct 1, 2019
ArtelMike pushed a commit to ArtelMike/openwrt-1 that referenced this issue Jan 31, 2023
Go for openwrt passes pkg-config arguments in the format of

        pkg-config --cflags -- pkg-name

which in turn will be passed down to the real pkg-config as something
like

        pkg-config.real --cflags -- pkg-name --define...

and causes the real pkg-config implementation to missinterpret the given
argument list.

This also helps to fix golang/go#27940

Signed-off-by: Arthur Skowronek <arthur.skowronek@tuta.io>
(cherry picked from commit da2798a)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants