Interop with cc_* rules
Bazel

Interop with cc_* rules


Overview

These rules are temporary and will be deprecated in the future.


cc_interop_info

cc_interop_info(ctx)

Gather information from any CC dependencies.

Internal function - do not use.

Returns: CcInteropInfo: Information needed for CC interop.

Attributes

ctx

Unknown; Required

Rule context.


cc_haskell_import

cc_haskell_import(name, dep)

Exports a Haskell library as a CC library.

Given a haskell_library or haskell_binary input, outputs the shared object files produced as well as the object files it depends on directly and transitively. This is very useful if you want to link in a Haskell shared library from cc_library.

There is a caveat: this will not provide any shared libraries that aren't explicitly given to it. This means that if you're using prebuilt_dependencies and relying on GHC to provide those objects, they will not be present here. You will have to provide those separately to your cc_library. If you're getting prebuilt_dependencies from your toolchain, you will likely want to extract those and pass them in as well.

This rule is temporary and only needed until the Bazel C/C++ "sandwich" (see bazelbuild/bazel#2163) is implemented. This rule will be deprecated in the future.

Attributes

name

Name; Required

A unique name for this rule.

dep

Label; Optional

Target providing a HaskellLibraryInfo or HaskellBinaryInfo, such as haskell_library or haskell_binary.

Examples

haskell_library(
  name = "my-lib",
  ...
)

cc_haskell_import(
  name = "my-lib-objects",
  dep = ":my-lib",
)

cc_library(
  name = "my-cc",
  srcs = ["main.c", ":my-lib-objects"],
)

haskell_cc_import

haskell_cc_import(name, hdrs, shared_library, strip_include_prefix)

Imports a prebuilt shared library.

Use this to make .so, .dll, .dylib files residing in external external repositories available to Haskell rules.

This rule is temporary replacement for cc_import and will be deprecated in the future.

Attributes

name

Name; Required

A unique name for this rule.

hdrs

List of labels; Optional; Default is []

The list of header files published by this precompiled library to be directly included by sources in dependent rules.

shared_library

Label; Optional

A single precompiled shared library.

Bazel ensures it is available to the binary that depends on it during runtime.

strip_include_prefix

String; Optional; Default is ''

The prefix to strip from the paths of the headers of this rule. When set, the headers in the hdrs attribute of this rule are accessible at their path (relative to the repository) with this prefix cut off.

If it's a relative path, it's taken as a package-relative one. If it's an absolute one, it's understood as a repository-relative path.

Examples

haskell_cc_import(name = "zlib", shared_library = "@zlib//:lib")

haskell_binary(
  name = "crc32sum",
  srcs = ["Main.hs"],
  deps = [":zlib"],
  prebuilt_dependencies = ["base"],
)