bazel-contrib / bazel-contrib/rules_go

Protoc execution does not honor LD_LIBRARY_PATH

Open
#2,265 0 comments 3 reactions 0 assignees View on GitHub
bug proto
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

### What version of rules_go are you using?

0.20.1

### What version of gazelle are you using?

0.19.0

### What version of Bazel are you using?

1.0.0

### Does this issue reproduce with the latest releases of all the above?

All are latest releases.

### What operating system and processor architecture are you using?

GNU/Linux 4.14.13-1.el7.elrepo.x86_64

### Any other potentially useful information about your toolchain?

N/A

### What did you do?

I do compile on a machine which `LD_LIBRARY_PATH` set to a non-standard location.
Compilation of `protoc` works fine, and the environment is detected appropriately:

```
SUBCOMMAND: # @com_google_protobuf//:protoc_lib [action 'Compiling external/com_google_protobuf/src/google/protobuf/compiler/java/java_extension_lite.cc [for host]', configuration: 0e826bf0d9108ecc0da83fd1b 5b426a3]
(cd /home/pmatri/.cache/bazel/_bazel_pmatri/f2c77c893130d35a993f4ab14a972dcb/execroot/atlas && \
exec env - \
LD_LIBRARY_PATH=/devtools/devtools-eaf9d86f/lib64 \
PATH=/devtools/devtools-eaf9d86f/bin:/devtools/devtools-eaf9d86f/jdk/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/pmatri/bin \
PWD=/proc/self/cwd \
/devtools/devtools-eaf9d86f/bin/gcc [...]
```

When running `protoc` however, the rule does not pass `LD_LIBRARY_PATH` appropriately:

```
@io_bazel_rules_go//proto/wkt:duration_go_proto [action 'Generating into bazel-out/k8-fastbuild/bin/external/io_bazel_rules_go/proto/wkt/linux_amd64_stripped/duration_go_proto%/github.com/gola ng/protobuf/ptypes/duration', configuration: d534253f7f366fdfbb590befef52e47f]
(cd /home/pmatri/.cache/bazel/_bazel_pmatri/f2c77c893130d35a993f4ab14a972dcb/execroot/atlas && \
exec env - \
CGO_ENABLED=1 \
GOARCH=amd64 \
GOOS=linux \
GOROOT=external/go_sdk \
GOROOT_FINAL=GOROOT \
PATH=/devtools/devtools-eaf9d86f/bin:/bin:/usr/bin \
bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders/linux_amd64_stripped/go-protoc -protoc bazel-out/host/bin/external/com_google_protobuf/protoc [...]
```

Because `LD_LIBRARY_PATH` is unset, execution fails:

```
ERROR: /home/pmatri/.cache/bazel/_bazel_pmatri/f2c77c893130d35a993f4ab14a972dcb/external/io_bazel_rules_go/proto/wkt/BUILD.bazel:3:1: Generating into bazel-out/k8-fastbuild/bin/external/io_bazel_rules_go/proto/wkt/linux_amd64_stripped/source_context_go_proto%/google.golang.org/genproto/protobuf/source_context failed (Exit 1) go-protoc failed: error executing command bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders/linux_amd64_stripped/go-protoc -protoc bazel-out/host/bin/external/com_google_protobuf/protoc -importpath ... (remaining 12 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
bazel-out/host/bin/external/com_google_protobuf/protoc: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by bazel-out/host/bin/external/com_google_protobuf/protoc)
bazel-out/host/bin/external/com_google_protobuf/protoc: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by bazel-out/host/bin/external/com_google_protobuf/protoc)
bazel-out/host/bin/external/com_google_protobuf/protoc: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by bazel-out/host/bin/external/com_google_protobuf/protoc)
```

I can replicate the issue myself:

```
-bash-4.2$ LD_LIBRARY_PATH="" bazel-out/host/bin/external/com_google_protobuf/protoc
bazel-out/host/bin/external/com_google_protobuf/protoc: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by bazel-out/host/bin/external/com_google_protobuf/protoc)
bazel-out/host/bin/external/com_google_protobuf/protoc: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by bazel-out/host/bin/external/com_google_protobuf/protoc)
bazel-out/host/bin/external/com_google_protobuf/protoc: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by bazel-out/host/bin/external/com_google_protobuf/protoc)
```

Running protoc with the correct `LD_LIBRARY_PATH` works.

### What did you expect to see?

I would expect `LD_LIBRARY_PATH` to be set when executing `protoc-go`

### What did you see instead?

`LD_LIBRARY_PATH` is unset when executing `protoc-go`, although present in the environment and used to compile `protoc` in the first place.

Contributor guide

Open the contributing guide

Research direction

Start with the @io_bazel_rules_go//proto/wkt action and the go-protoc entry point shown at bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders/linux_amd64_stripped/go-protoc. Compare its execution environment with the protoc compilation environment, then reproduce the failure using the external/com_google_protobuf/protoc command. Done means proto generation can execute protoc with the required LD_LIBRARY_PATH.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.