bazel-contrib / musl-toolchain

Apache License 2.0
15 stars 2 forks source link

Can't import grpc with rules_python #36

Open juanzolotoochin opened 3 months ago

juanzolotoochin commented 3 months ago

When using this toolchain when I do:

from examples.grpc.protos import helloworld_pb2_grpc

I get the following error:

Traceback (most recent call last):
  File "/home/juanique/.cache/bazel/_bazel_juanique/05c4bafe3bdc03c8ced122f9ff172535/sandbox/linux-sandbox/7866/execroot/monorepo/bazel-out/k8-fastbuild/bin/examples/repro/grpc_import.runfiles/monorepo/examples/repro/grpc_import.py", line 2, in <module>
    from examples.grpc.protos import helloworld_pb2_grpc
  File "/home/juanique/.cache/bazel/_bazel_juanique/05c4bafe3bdc03c8ced122f9ff172535/sandbox/linux-sandbox/7866/execroot/monorepo/bazel-out/k8-fastbuild/bin/examples/repro/grpc_import.runfiles/monorepo/examples/grpc/protos/helloworld_pb2_grpc.py", line 3, in <module>
    import grpc
  File "/home/juanique/.cache/bazel/_bazel_juanique/05c4bafe3bdc03c8ced122f9ff172535/sandbox/linux-sandbox/7866/execroot/monorepo/bazel-out/k8-fastbuild/bin/examples/repro/grpc_import.runfiles/com_github_grpc_grpc/src/python/grpcio/grpc/__init__.py", line 22, in <module>
    from grpc import _compression
  File "/home/juanique/.cache/bazel/_bazel_juanique/05c4bafe3bdc03c8ced122f9ff172535/sandbox/linux-sandbox/7866/execroot/monorepo/bazel-out/k8-fastbuild/bin/examples/repro/grpc_import.runfiles/com_github_grpc_grpc/src/python/grpcio/grpc/_compression.py", line 20, in <module>
    from grpc._cython import cygrpc
ImportError: /lib/x86_64-linux-gnu/libc.so: invalid ELF header

The same import works fine with the same workspace state but using the zig hermetic toolchain.

Here's a repro:

$ git clone https://github.com/juanique/monorepo.git
$ cd monorepo

# Clone a commit that is known to work without the musl toolchain
$ git checkout 4eeced95

# Verify that it passes with existing (zig hermetic c++) toolchain:
$ bazel test //examples/repro:grpc_import
//examples/repro:grpc_import                                             PASSED in 0.3s

# checkout branch that switches to musl toolchain
$ git checkout switch_to_musl_toolc_0b204

# run test again
$ bazel test //examples/repro:grpc_import

//examples/repro:grpc_import                                             FAILED in 0.2s

Test logs show the error above.

The diff for the branch can be seen in the following PR: https://github.com/juanique/monorepo/pull/183