rules_haskell icon indicating copy to clipboard operation
rules_haskell copied to clipboard

ld: -rpath can only be used when creating a dynamic final linked image

Open aherrmann opened this issue 4 years ago • 0 comments

Describe the bug

haskell_cabal_library fails when deps includes a dynamically linked C library. The error is

ld: -rpath can only be used when creating a dynamic final linked image

To Reproduce

Checkout https://github.com/tweag/rules_haskell/commit/dd665688b6c15a195992b1c289ac32e69cd545b1 and execute

bazel build @stackage-zlib//:zlib

on MacOS in bindist mode.

The stack_snapshot looks like this:

stack_snapshot(
    name = "stackage-zlib",
    extra_deps = {"zlib": ["@zlib.dev//:zlib" if is_nix_shell else "@zlib.hs//:zlib"]},
    packages = ["zlib"],
    snapshot = "lts-13.15",
)

And @zlib.hs like this:

http_archive(
    name = "zlib.hs",
    build_file_content = """
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
    name = "zlib",
    # Import `:z` as `srcs` to enforce the library name `libz.so`. Otherwise,
    # Bazel would mangle the library name and e.g. Cabal wouldn't recognize it.
    srcs = [":z"],
    hdrs = glob(["*.h"]),
    includes = ["."],
    visibility = ["//visibility:public"],
)
cc_library(name = "z", srcs = glob(["*.c"]), hdrs = glob(["*.h"]))
""",
    sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
    strip_prefix = "zlib-1.2.11",
    urls = [
        "https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz",
        "http://zlib.net/zlib-1.2.11.tar.gz",
    ],
)

Expected behavior The build should succeed without error.

Environment

  • OS name + version: MacOS 10.14.6
  • Bazel version: 2.1.0
  • Version of the rules: 0b86a258ce2ebe56cd50279d38a41f5bf2c68175

Additional context

  • CI run https://circleci.com/gh/tweag/rules_haskell/8976?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-checks-link
  • We pass --ghc-option=-optl-Wl,-rpath,... to Cabal in order to define correct RUNPATH entries for Cabal libraries. See https://github.com/tweag/rules_haskell/pull/1282 and https://github.com/tweag/rules_haskell/pull/1267. The issue seems to be that Cabal and GHC forward these flags in the dynamic and static linking cases. On MacOS ld seems to forbid -rpath in the latter case.

aherrmann avatar Apr 30 '20 16:04 aherrmann