Skip to content

Commit

Permalink
Enable profiling builds of Cabal packages (#6240)
Browse files Browse the repository at this point in the history
* Upgrade rules_haskell to latest master

changelog_begin
changelog_end

* Update rules_haskell

* Cabal: Track _p.a and .a outputs

CHANGELOG_BEGIN
CHANGELOG_END

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
  • Loading branch information
3 people authored Jun 8, 2020
1 parent 1836905 commit 921266a
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 28 deletions.
23 changes: 0 additions & 23 deletions bazel_tools/haskell-pgmc.patch

This file was deleted.

316 changes: 316 additions & 0 deletions bazel_tools/haskell-profiling.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
diff --git a/haskell/cabal.bzl b/haskell/cabal.bzl
index e44f9b45..6f73fa8f 100644
--- a/haskell/cabal.bzl
+++ b/haskell/cabal.bzl
@@ -249,11 +249,9 @@ def _prepare_cabal_inputs(
depset(transitive_link_libs),
depset(transitive_haddocks),
setup_dep_info.interface_dirs,
- setup_dep_info.static_libraries,
- setup_dep_info.dynamic_libraries,
+ setup_dep_info.hs_libraries,
dep_info.interface_dirs,
- dep_info.static_libraries,
- dep_info.dynamic_libraries,
+ dep_info.hs_libraries,
tool_inputs,
],
)
@@ -338,13 +336,19 @@ def _haskell_cabal_library_impl(ctx):
else:
haddock_file = None
haddock_html_dir = None
- static_library_filename = "_install/lib/libHS{}.a".format(package_id)
- if with_profiling:
- static_library_filename = "_install/lib/libHS{}_p.a".format(package_id)
- static_library = hs.actions.declare_file(
- static_library_filename,
+ vanilla_library = hs.actions.declare_file(
+ "_install/lib/libHS{}.a".format(package_id),
sibling = cabal,
)
+ if with_profiling:
+ profiling_library = hs.actions.declare_file(
+ "_install/lib/libHS{}_p.a".format(package_id),
+ sibling = cabal,
+ )
+ static_library = profiling_library
+ else:
+ profiling_library = None
+ static_library = vanilla_library
if hs.toolchain.is_static:
dynamic_library = None
else:
@@ -387,13 +391,15 @@ def _haskell_cabal_library_impl(ctx):
outputs = [
package_database,
interfaces_dir,
- static_library,
+ vanilla_library,
data_dir,
]
if ctx.attr.haddock:
outputs.extend([haddock_file, haddock_html_dir])
if dynamic_library != None:
outputs.append(dynamic_library)
+ if with_profiling:
+ outputs.append(profiling_library)
ctx.actions.run(
executable = c.cabal_wrapper,
arguments = [c.args],
@@ -419,15 +425,11 @@ def _haskell_cabal_library_impl(ctx):
source_files = depset(),
extra_source_files = depset(),
import_dirs = set.empty(),
- static_libraries = depset(
- direct = [static_library],
- transitive = [dep_info.static_libraries],
+ hs_libraries = depset(
+ direct = [lib for lib in [vanilla_library, dynamic_library, profiling_library] if lib],
+ transitive = [dep_info.hs_libraries],
order = "topological",
),
- dynamic_libraries = depset(
- direct = [dynamic_library] if dynamic_library != None else [],
- transitive = [dep_info.dynamic_libraries],
- ),
interface_dirs = depset([interfaces_dir], transitive = [dep_info.interface_dirs]),
compile_flags = [],
)
@@ -668,8 +670,7 @@ def _haskell_cabal_binary_impl(ctx):
source_files = depset(),
extra_source_files = depset(),
import_dirs = set.empty(),
- static_libraries = dep_info.static_libraries,
- dynamic_libraries = dep_info.dynamic_libraries,
+ hs_libraries = dep_info.hs_libraries,
interface_dirs = dep_info.interface_dirs,
compile_flags = [],
)
diff --git a/haskell/doctest.bzl b/haskell/doctest.bzl
index 1578efbc..2e32d3fe 100644
--- a/haskell/doctest.bzl
+++ b/haskell/doctest.bzl
@@ -128,7 +128,7 @@ def _haskell_doctest_single(target, ctx):
hs_info.package_databases,
hs_info.interface_dirs,
hs_info.extra_source_files,
- hs_info.dynamic_libraries,
+ hs_info.hs_libraries,
cc_info.compilation_context.headers,
depset(get_ghci_library_files(hs, cc_libraries_info, cc.transitive_libraries)),
depset(
diff --git a/haskell/haddock.bzl b/haskell/haddock.bzl
index 18265c08..dfcff942 100644
--- a/haskell/haddock.bzl
+++ b/haskell/haddock.bzl
@@ -162,7 +162,7 @@ def _haskell_doc_aspect_impl(target, ctx):
target[HaskellInfo].interface_dirs,
target[HaskellInfo].source_files,
target[HaskellInfo].extra_source_files,
- target[HaskellInfo].dynamic_libraries,
+ target[HaskellInfo].hs_libraries,
depset(cc_libraries),
depset(transitive = [depset(i) for i in transitive_haddocks.values()]),
target[CcInfo].compilation_context.headers,
diff --git a/haskell/private/actions/compile.bzl b/haskell/private/actions/compile.bzl
index 5bec4abc..b31790fc 100644
--- a/haskell/private/actions/compile.bzl
+++ b/haskell/private/actions/compile.bzl
@@ -347,12 +347,10 @@ def _compilation_defaults(hs, cc, java, posix, dep_info, plugin_dep_info, srcs,
depset(cc.hdrs),
dep_info.package_databases,
dep_info.interface_dirs,
- dep_info.static_libraries,
- dep_info.dynamic_libraries,
+ dep_info.hs_libraries,
plugin_dep_info.package_databases,
plugin_dep_info.interface_dirs,
- plugin_dep_info.static_libraries,
- plugin_dep_info.dynamic_libraries,
+ plugin_dep_info.hs_libraries,
depset(get_ghci_library_files(hs, cc.cc_libraries_info, cc.transitive_libraries + cc.plugin_libraries)),
java.inputs,
preprocessors.inputs,
diff --git a/haskell/private/actions/info.bzl b/haskell/private/actions/info.bzl
index 692b4906..ab4e5f84 100644
--- a/haskell/private/actions/info.bzl
+++ b/haskell/private/actions/info.bzl
@@ -133,7 +133,7 @@ def library_info_output_groups(
transitive = [
hs_info.package_databases,
hs_info.interface_dirs,
- hs_info.dynamic_libraries,
+ hs_info.hs_libraries,
],
),
"haskell_library_info": depset([proto_file]),
diff --git a/haskell/private/actions/link.bzl b/haskell/private/actions/link.bzl
index e9782573..18ac11b1 100644
--- a/haskell/private/actions/link.bzl
+++ b/haskell/private/actions/link.bzl
@@ -129,8 +129,7 @@ def link_binary(
inputs = depset(transitive = [
depset(extra_srcs),
dep_info.package_databases,
- dep_info.dynamic_libraries,
- dep_info.static_libraries,
+ dep_info.hs_libraries,
depset([cache_file] + object_files),
pkg_info_inputs,
depset(static_libs + dynamic_libs),
@@ -248,7 +247,7 @@ def link_library_dynamic(hs, cc, posix, dep_info, extra_srcs, object_files, my_p
inputs = depset([cache_file] + object_files, transitive = [
extra_srcs,
dep_info.package_databases,
- dep_info.dynamic_libraries,
+ dep_info.hs_libraries,
pkg_info_inputs,
depset(static_libs + dynamic_libs),
]),
diff --git a/haskell/private/dependencies.bzl b/haskell/private/dependencies.bzl
index f7090725..33a97e64 100644
--- a/haskell/private/dependencies.bzl
+++ b/haskell/private/dependencies.bzl
@@ -21,13 +21,8 @@ def gather_dep_info(ctx, deps):
for dep in deps
if HaskellInfo in dep
])
- static_libraries = depset(transitive = [
- dep[HaskellInfo].static_libraries
- for dep in deps
- if HaskellInfo in dep
- ])
- dynamic_libraries = depset(transitive = [
- dep[HaskellInfo].dynamic_libraries
+ hs_libraries = depset(transitive = [
+ dep[HaskellInfo].hs_libraries
for dep in deps
if HaskellInfo in dep
])
@@ -62,8 +57,7 @@ def gather_dep_info(ctx, deps):
acc = HaskellInfo(
package_databases = package_databases,
version_macros = set.empty(),
- static_libraries = static_libraries,
- dynamic_libraries = dynamic_libraries,
+ hs_libraries = hs_libraries,
interface_dirs = interface_dirs,
source_files = source_files,
import_dirs = import_dirs,
@@ -79,8 +73,7 @@ def gather_dep_info(ctx, deps):
acc = HaskellInfo(
package_databases = acc.package_databases,
version_macros = set.mutable_union(acc.version_macros, binfo.version_macros),
- static_libraries = depset(transitive = [acc.static_libraries, binfo.static_libraries]),
- dynamic_libraries = acc.dynamic_libraries,
+ hs_libraries = depset(transitive = [acc.hs_libraries, binfo.hs_libraries]),
interface_dirs = acc.interface_dirs,
import_dirs = import_dirs,
compile_flags = compile_flags,
@@ -97,8 +90,7 @@ def gather_dep_info(ctx, deps):
import_dirs = acc.import_dirs,
source_files = acc.source_files,
compile_flags = acc.compile_flags,
- static_libraries = acc.static_libraries,
- dynamic_libraries = acc.dynamic_libraries,
+ hs_libraries = acc.hs_libraries,
extra_source_files = acc.extra_source_files,
interface_dirs = acc.interface_dirs,
)
diff --git a/haskell/private/haskell_impl.bzl b/haskell/private/haskell_impl.bzl
index 7ddb4625..a53b2d62 100644
--- a/haskell/private/haskell_impl.bzl
+++ b/haskell/private/haskell_impl.bzl
@@ -232,8 +232,7 @@ def _haskell_binary_common_impl(ctx, is_test):
source_files = c.source_files,
extra_source_files = c.extra_source_files,
import_dirs = c.import_dirs,
- static_libraries = dep_info.static_libraries,
- dynamic_libraries = dep_info.dynamic_libraries,
+ hs_libraries = dep_info.hs_libraries,
interface_dirs = dep_info.interface_dirs,
compile_flags = c.compile_flags,
)
@@ -405,19 +404,8 @@ def haskell_library_impl(ctx):
my_pkg_id,
with_profiling = with_profiling,
)
-
- # NOTE We have to use lists for static libraries because the order is
- # important for linker. Linker searches for unresolved symbols to the
- # left, i.e. you first feed a library which has unresolved symbols and
- # then you feed the library which resolves the symbols.
- static_libraries = depset(
- direct = [static_library],
- transitive = [dep_info.static_libraries],
- order = "topological",
- )
else:
static_library = None
- static_libraries = dep_info.static_libraries

if with_shared and srcs_files:
dynamic_library = link_library_dynamic(
@@ -430,10 +418,8 @@ def haskell_library_impl(ctx):
my_pkg_id,
user_compile_flags,
)
- dynamic_libraries = depset([dynamic_library], transitive = [dep_info.dynamic_libraries])
else:
dynamic_library = None
- dynamic_libraries = dep_info.dynamic_libraries

conf_file, cache_file = package(
hs,
@@ -468,8 +454,10 @@ def haskell_library_impl(ctx):
source_files = c.source_files,
extra_source_files = c.extra_source_files,
import_dirs = set.mutable_union(c.import_dirs, export_infos.import_dirs),
- static_libraries = depset(transitive = [static_libraries, export_infos.static_libraries]),
- dynamic_libraries = depset(transitive = [dynamic_libraries, export_infos.dynamic_libraries]),
+ hs_libraries = depset(
+ direct = [lib for lib in [static_library, dynamic_library] if lib],
+ transitive = [dep_info.hs_libraries, export_infos.hs_libraries],
+ ),
interface_dirs = depset(transitive = [interface_dirs, export_infos.interface_dirs]),
compile_flags = c.compile_flags,
)
@@ -815,8 +803,8 @@ def haskell_import_impl(ctx):
source_files = depset(),
extra_source_files = depset(),
import_dirs = set.empty(),
- static_libraries = depset(),
- dynamic_libraries = depset(),
+ # XXX: Track toolchain library files of all relevant GHC ways.
+ hs_libraries = depset(),
interface_dirs = depset(),
compile_flags = [],
)
diff --git a/haskell/providers.bzl b/haskell/providers.bzl
index fb220e16..ab2cc586 100644
--- a/haskell/providers.bzl
+++ b/haskell/providers.bzl
@@ -8,8 +8,7 @@ HaskellInfo = provider(
"import_dirs": "Import hierarchy roots.",
"source_files": "Depset of files that contain Haskell modules.",
"extra_source_files": "Depset of non-Haskell source files.",
- "static_libraries": "Ordered collection of compiled library archives.",
- "dynamic_libraries": "Depset of dynamic libraries.",
+ "hs_libraries": "Depset of compiled Haskell libraries in all available GHC ways.",
"interface_dirs": "Depset of interface dirs belonging to the packages.",
"compile_flags": "Arguments that were used to compile the code.",
},
diff --git a/tests/library-linkstatic-flag/get_library_files.bzl b/tests/library-linkstatic-flag/get_library_files.bzl
index 0c73965c..e3413ecf 100644
--- a/tests/library-linkstatic-flag/get_library_files.bzl
+++ b/tests/library-linkstatic-flag/get_library_files.bzl
@@ -12,7 +12,7 @@ def _get_libraries_as_runfiles_impl(ctx):
return [DefaultInfo(
# not necessarily complete
files = depset(
- transitive = [bi.static_libraries, bi.dynamic_libraries],
+ transitive = [bi.hs_libraries],
),
)]

2 changes: 1 addition & 1 deletion compatibility/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def daml_deps():
"@daml//bazel_tools:haskell-strict-source-names.patch",
"@daml//bazel_tools:haskell-windows-remove-fake-libs.patch",
"@daml//bazel_tools:haskell-windows-extra-libraries.patch",
"@daml//bazel_tools:haskell-pgmc.patch",
"@daml//bazel_tools:haskell-profiling.patch",
],
patch_args = ["-p1"],
sha256 = rules_haskell_sha256,
Expand Down
8 changes: 4 additions & 4 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
rules_scala_version = "6c16cff213b76a4126bdc850956046da5db1daaa"
rules_scala_sha256 = "132cf8eeaab67f3142cec17152b8415901e7fa8396dd585d6334eec21bf7419d"

rules_haskell_version = "ac87721a4dbc0f7dbe731df928d322f02ed93330"
rules_haskell_sha256 = "684f91defad36e9d6ce3ac4213864b89e8f6fe813508ae93bfe80996447a1516"
rules_haskell_version = "98e3fb73dca350c12892ec6476a3bb80a04d87b4"
rules_haskell_sha256 = "2e39f897cee3fef02b7d941126ca808f3a74c702d9a9f1fb2810bfd7da9946d4"
rules_nixpkgs_version = "d3c7bc94fed4001d5375632a936d743dc085c9a1"
rules_nixpkgs_sha256 = "903c6b98aa6a298bf45a6b931e77a3313c40a0cb1b44fa00d9792f9e8aedbb35"
buildifier_version = "0.26.0"
Expand Down Expand Up @@ -78,8 +78,8 @@ def daml_deps():
# This should be made configurable in rules_haskell.
# Remove this patch once that's available.
"@com_github_digital_asset_daml//bazel_tools:haskell-opt.patch",
# This can be upstreamed.
"@com_github_digital_asset_daml//bazel_tools:haskell-pgmc.patch",
# Remove once merged upstream.
"@com_github_digital_asset_daml//bazel_tools:haskell-profiling.patch",
],
patch_args = ["-p1"],
sha256 = rules_haskell_sha256,
Expand Down

0 comments on commit 921266a

Please sign in to comment.