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

turn relative path to absolute path in environment's cgo's flags #1536

Merged
merged 1 commit into from Jun 19, 2018
Merged

turn relative path to absolute path in environment's cgo's flags #1536

merged 1 commit into from Jun 19, 2018

Conversation

bennyscetbun
Copy link
Contributor

@bennyscetbun bennyscetbun commented Jun 8, 2018

This pr can be merge as it, but it s main focus is to discuss a "rules_go" way to fix the problem.

Problem:
cgo flags will sometime be setup with relative path in the environment but Go will make its own sandbox and wont be able to use those path.

Solution:
make all the path absolute in cgo environment variable.

I have no better solution than to embbed shlex in rules_go and use it on the environmnet variables.

@bennyscetbun
Copy link
Contributor Author

something went wrong with travis... Could you restart it ?

Copy link
Contributor

@jayconrod jayconrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! Sorry I wasn't able to review earlier.

I agree with the overall goal of this PR, but I'd like to suggest a couple changes to the implementation.

  1. The Go tools don't interpret quotes or escapes in cgo flags passed as environment variables. See envList in cmd/go/internal/work/exec.go; it just uses strings.Fields to split up the flags. We can do the same; we shouldn't use shlex.go for this.

  2. Since this process is pretty invasive, there should be an explicit function that does this for a list of environment variables. Let's call it absEnv.

  3. We don't pass cgo flags to most builders. This function only needs to be called in cgo.go and stdlib.go.

@bennyscetbun
Copy link
Contributor Author

okay will work on that

@bennyscetbun
Copy link
Contributor Author

Hey @jayconrod
I ve done what you ve suggested.
Could you check again ?

@@ -180,6 +180,12 @@ func run(args []string) error {
}
}

// Modifying CGO flags to use only absolute path
// because go is having its own sandbox, all CGO flags must use absolute path
if err := absEnv([]string{"CGO_CFLAGS", "CGO_CXXFLAGS", "CGO_CPPFLAGS", "CGO_LDFLAGS"}, []string{"-I", "-L", "-isysroot", "-isystem", "-iquote", "-include", "-gcc-toolchain", "--sysroot"}); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps they should be defined in a global variable up in env.go

@jayconrod
Copy link
Contributor

Change looks good, but some tests are failing on BuildKite. Specifically //tests/core/cgo:dylib_test seems to be broken. Mind taking a look?

external/go_sdk/pkg/tool/darwin_amd64/link: running external/local_config_cc/cc_wrapper.sh failed: exit status 1
ld: warning: directory not found for option '-L/private/var/tmp/_bazel_buildkite/be4b3196a21ee19508aa8fdc35451a6f/sandbox/darwin-sandbox/2028/execroot/io_bazel_rules_go/bazel-out/darwin-fastbuild/bin/_solib_darwin_x86_64/_U_S_Stests_Score_Scgo_Cdarwin_Uimported_Udylib___Utests_Score_Scgo'
ld: library not found for -limported
clang: error: linker command failed with exit code 1 (use -v to see invocation)
GoLink: error running subcommand: exit status 2

@bennyscetbun
Copy link
Contributor Author

on it

@bennyscetbun
Copy link
Contributor Author

bennyscetbun commented Jun 19, 2018

i ve removed absEnv from cgo.go. It s only useful in stdlib.go which is build with go build.

@jayconrod jayconrod merged commit a576593 into bazelbuild:master Jun 19, 2018
@jayconrod
Copy link
Contributor

Merged. Thanks for submitting this.

I guess it makes sense this wouldn't be needed in cgo -- only the stdlib builder changes the working directory internally. Other builders should be able to tolerate relative paths.

@zllak zllak deleted the fix/android_absolute_path branch June 19, 2018 16:55
zecke added a commit to zecke/rules_go that referenced this pull request Nov 9, 2023
Make the gopackagesdriver work when using a C/C++ toolchain with
sysroots. We need to turn the relative in flag like --sysroot into
an absolute.

Address the todo by using the code already available in the stdlib.go
as part of bazelbuild#1536.
fmeum pushed a commit that referenced this pull request Nov 9, 2023
Make the gopackagesdriver work when using a C/C++ toolchain with
sysroots. We need to turn the relative in flag like --sysroot into
an absolute.

Address the todo by using the code already available in the stdlib.go
as part of #1536.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants