Skip to content

Commit bb14958

Browse files
authored
Merge branch 'master' into cb/update-rules_sh
2 parents 5f0ebc0 + d18915c commit bb14958

File tree

15 files changed

+391
-333
lines changed

15 files changed

+391
-333
lines changed

.bazelrc.common

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ common --incompatible_disallow_empty_glob=true
2323
# as LOCALE_ARCHIVE We also need to setup an utf8 locale
2424
test --test_env=LANG=C.UTF-8 --test_env=LOCALE_ARCHIVE
2525

26+
# Enable automatic OS-specific config (e.g. build:linux, build:macos, build:windows).
27+
common --enable_platform_specific_config
28+
29+
# MacOS Configuration
30+
# -------------------
31+
# do not use Xcode on macOS
32+
common:macos --repo_env=BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
33+
34+
# Windows Configuration
35+
# ---------------------
36+
# prevent auto-detection of system compilers on Windows
37+
common:windows --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
38+
2639
# Platform / Toolchain Selection
2740
# ------------------------------
2841
build:linux-nixpkgs --config=nixpkgs

.bcr/rules_haskell/presubmit.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ tasks:
1111
verify_targets:
1212
name: Verify build targets
1313
platform: ${{ platform }}
14-
environment:
15-
BAZEL_USE_CPP_ONLY_TOOLCHAIN: '1'
1614
shell_commands:
1715
- |
1816
if apt --version >/dev/null 2>/dev/null; then
@@ -22,7 +20,6 @@ tasks:
2220
batch_commands:
2321
# enforce certificate update
2422
- 'powershell -Command "Invoke-WebRequest -Uri https://hackage.haskell.org/root.json -OutFile out.json"'
25-
- set BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
2623
build_flags:
2724
- '--incompatible_enable_cc_toolchain_resolution'
2825
build_targets:

.github/workflows/patch-test.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ jobs:
7272
shell: bash
7373
run: |
7474
export PATH=$HOME/bazel:$PATH
75-
[[ ${{ runner.os }} == macOS ]] && export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
7675
export GHC_VERSION=${{ matrix.ghc-version }}
7776
cd rules_haskell_tests
7877
./tests/run-start-script.sh --use-bindists

.github/workflows/workflow.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ jobs:
130130
# Shutdown Bazel to free up memory
131131
# https://github.com/tweag/rules_haskell/issues/2089.
132132
bazel shutdown
133-
./bazel-ci-bin/tests/run-tests
133+
# Execute the tests dumping out memory/process information before and after each test.
134+
RHT_PRINT_MEMORY=true ./bazel-ci-bin/tests/run-tests
134135
bazel coverage //...
135136
136137
test-bindist:
@@ -156,10 +157,6 @@ jobs:
156157
- ghc: 9.6.2
157158
os: windows-latest
158159
env:
159-
# prevent auto-detection of system compilers on Windows
160-
BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN: ${{ matrix.os == 'windows-latest' && 1 || 0 }}
161-
# do not use Xcode on macOS
162-
BAZEL_USE_CPP_ONLY_TOOLCHAIN: ${{ matrix.os == 'macos-latest' && 1 || 0 }}
163160
GHC_VERSION: ${{ matrix.ghc }}
164161
runs-on: ${{ matrix.os }}
165162
steps:

README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ If you are on NixOS, this is the only way to set up your project,
7676
because the GHC toolchain provisioned through binary distributions
7777
cannot be executed on NixOS.
7878

79-
If you are on macOS, you will have to set the environment variable
80-
`BAZEL_USE_CPP_ONLY_TOOLCHAIN = 1`, so that Bazel picks the correct C compiler.
81-
8279
[bazel-cli-commands]: https://docs.bazel.build/versions/master/command-line-reference.html#commands
8380
[nixpkgs]: https://nixos.org/nixpkgs/
8481

@@ -227,14 +224,6 @@ en_US.utf8
227224
POSIX
228225
```
229226

230-
### MacOS: Error: DEVELOPER_DIR not set.
231-
232-
Make sure to set the following environment variable:
233-
```
234-
export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
235-
```
236-
This ensures that Bazel picks the correct C compiler.
237-
238227
### Windows: Incorrect `cc_toolchain` used
239228

240229
If you're using Windows, bazel might use a different `cc_toolchain`

haskell/BUILD.bazel

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
3-
load(
4-
"@rules_haskell//haskell:private/haskell_impl.bzl",
5-
"haskell_toolchain_libraries",
6-
)
73
load(
84
"@rules_haskell//haskell:private/cc_wrapper.bzl",
95
"cc_wrapper",
@@ -167,10 +163,6 @@ toolchain_type(
167163
# implemented, yet. See
168164
# https://github.com/bazelbuild/proposals/blob/master/designs/2019-02-12-toolchain-transitions.md
169165
# This will need to be revisited once that proposal is implemented.
170-
haskell_toolchain_libraries(
171-
name = "toolchain-libraries",
172-
visibility = ["//visibility:public"],
173-
)
174166

175167
config_setting(
176168
name = "use_worker",

haskell/defs.bzl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,6 @@ haskell_toolchain_library = rule(
670670
package = attr.string(
671671
doc = "The name of a GHC package not built by Bazel. Defaults to the name of the rule.",
672672
),
673-
_toolchain_libraries = attr.label(
674-
default = Label("@rules_haskell//haskell:toolchain-libraries"),
675-
),
676673
),
677674
toolchains = [
678675
"@rules_haskell//haskell:toolchain",

haskell/private/haskell_impl.bzl

Lines changed: 2 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Implementation of core Haskell rules"""
22

33
load("@bazel_skylib//lib:dicts.bzl", "dicts")
4-
load("@rules_cc//cc:find_cc_toolchain.bzl", "use_cc_toolchain")
54
load(
65
":providers.bzl",
76
"C2hsLibraryInfo",
@@ -35,9 +34,7 @@ load(":private/mode.bzl", "is_profiling_enabled")
3534
load(
3635
":private/path_utils.bzl",
3736
"determine_module_names",
38-
"get_dynamic_hs_lib_name",
3937
"get_lib_extension",
40-
"get_static_hs_lib_name",
4138
"infer_main_module",
4239
"match_label",
4340
"parse_pattern",
@@ -795,7 +792,8 @@ def haskell_toolchain_library_impl(ctx):
795792
else:
796793
package = ctx.label.name
797794

798-
libraries = ctx.attr._toolchain_libraries[HaskellToolchainLibraries].libraries
795+
libraries = hs.toolchain.new_libraries.libraries
796+
799797
target = libraries.get(package)
800798

801799
if not target:
@@ -823,154 +821,6 @@ The following toolchain libraries are available:
823821
)),
824822
]
825823

826-
def _toolchain_library_symlink(dynamic_library):
827-
prefix = dynamic_library.owner.workspace_root.replace("_", "_U").replace("/", "_S")
828-
basename = dynamic_library.basename
829-
return paths.join(prefix, basename)
830-
831-
def haskell_toolchain_libraries_impl(ctx):
832-
hs = haskell_context(ctx)
833-
with_profiling = is_profiling_enabled(hs)
834-
with_threaded = "-threaded" in hs.toolchain.ghcopts
835-
836-
cc_toolchain = find_cc_toolchain(ctx)
837-
feature_configuration = cc_common.configure_features(
838-
ctx = ctx,
839-
cc_toolchain = cc_toolchain,
840-
requested_features = ctx.features,
841-
unsupported_features = ctx.disabled_features,
842-
)
843-
844-
libraries = hs.toolchain.libraries
845-
846-
# List of library in left-to-right post-ordering
847-
# Meaning, if package B depends on package A, then A will appear before B.
848-
ordered = depset(transitive = [
849-
target[HaskellImportHack].transitive_depends
850-
for target in hs.toolchain.libraries.values()
851-
])
852-
853-
library_dict = {}
854-
for package in ordered.to_list():
855-
target = libraries[package]
856-
857-
# Construct CcInfo
858-
if with_profiling:
859-
# GHC does not provide dynamic profiling mode libraries. The dynamic
860-
# libraries that are available are missing profiling symbols, that
861-
# other profiling mode build results will reference. Therefore, we
862-
# don't import dynamic libraries in profiling mode.
863-
libs = {
864-
get_static_hs_lib_name(hs.toolchain.version, lib): {"static": lib}
865-
for lib in target[HaskellImportHack].static_profiling_libraries.to_list()
866-
}
867-
else:
868-
# Workaround for https://github.com/tweag/rules_haskell/issues/881
869-
# Static and dynamic libraries don't necessarily pair up 1 to 1.
870-
# E.g. the rts package in the Unix GHC bindist contains the
871-
# dynamic libHSrts and the static libCffi and libHSrts.
872-
libs = {}
873-
for lib in target[HaskellImportHack].dynamic_libraries.to_list():
874-
libname = get_dynamic_hs_lib_name(hs.toolchain.version, lib)
875-
if libname == "ffi" and libname in libs:
876-
# Make sure that the file of libffi matching its soname
877-
# ends up in target runfiles. Otherwise, execution will
878-
# fail with "cannot open shared object file" errors.
879-
# On Linux libffi comes in three shapes:
880-
# libffi.so, libffi.so.7, libffi.so.7.1.0
881-
# (version numbers may vary)
882-
# The soname is then libffi.so.7, meaning, at runtime the
883-
# dynamic linker will look for libffi.so.7. So, that file
884-
# should be the LibraryToLink.dynamic_library.
885-
ext_components = get_lib_extension(lib).split(".")
886-
if len(ext_components) == 2 and ext_components[0] == "so":
887-
libs[libname]["dynamic"] = lib
888-
else:
889-
libs[libname] = {"dynamic": lib}
890-
for lib in target[HaskellImportHack].static_libraries.to_list():
891-
name = get_static_hs_lib_name(with_profiling, lib)
892-
entry = libs.get(name, {})
893-
entry["static"] = lib
894-
libs[name] = entry
895-
896-
# Avoid duplicate runtime and ffi libraries. These libraries come
897-
# in threaded and non-threaded flavors. Depending on the
898-
# compilation mode we want to forward only one or the other.
899-
# XXX: Threaded mode should be a per-target property. Use Bazel
900-
# build configurations and transitions to select the threaded or
901-
# non-threaded runtime and ffi on a per-target basis.
902-
if "HSrts_thr" in libs:
903-
if with_threaded:
904-
libs["HSrts"] = libs["HSrts_thr"]
905-
libs.pop("HSrts_thr")
906-
if "Cffi_thr" in libs:
907-
if with_threaded:
908-
libs["ffi"]["static"] = libs["Cffi_thr"]["static"]
909-
libs.pop("Cffi_thr")
910-
linker_inputs = [
911-
cc_common.create_linker_input(
912-
owner = ctx.label,
913-
libraries = depset(direct = [
914-
cc_common.create_library_to_link(
915-
actions = ctx.actions,
916-
feature_configuration = feature_configuration,
917-
dynamic_library = lib.get("dynamic", None),
918-
dynamic_library_symlink_path =
919-
_toolchain_library_symlink(lib["dynamic"]) if lib.get("dynamic") else "",
920-
static_library = lib.get("static", None),
921-
cc_toolchain = cc_toolchain,
922-
)
923-
for lib in libs.values()
924-
]),
925-
user_link_flags = depset(direct = target[HaskellImportHack].linkopts),
926-
),
927-
]
928-
compilation_context = cc_common.create_compilation_context(
929-
headers = target[HaskellImportHack].headers,
930-
includes = target[HaskellImportHack].includes,
931-
)
932-
linking_context = cc_common.create_linking_context(
933-
linker_inputs = depset(direct = linker_inputs),
934-
)
935-
cc_info = CcInfo(
936-
compilation_context = compilation_context,
937-
linking_context = linking_context,
938-
)
939-
library_dict[package] = struct(
940-
default_info = target[DefaultInfo],
941-
hs_info = target[HaskellInfo],
942-
hs_lib_info = target[HaskellLibraryInfo],
943-
cc_info = cc_common.merge_cc_infos(cc_infos = [cc_info] + [
944-
library_dict[dep].cc_info
945-
for dep in target[HaskellImportHack].depends
946-
]),
947-
haddock_info = target[HaddockInfo],
948-
)
949-
950-
return [HaskellToolchainLibraries(libraries = library_dict)]
951-
952-
haskell_toolchain_libraries = rule(
953-
haskell_toolchain_libraries_impl,
954-
attrs = {
955-
"_cc_toolchain": attr.label(
956-
default = Label("@rules_cc//cc:current_cc_toolchain"),
957-
),
958-
},
959-
toolchains = use_cc_toolchain() + [
960-
"@rules_haskell//haskell:toolchain",
961-
],
962-
fragments = ["cpp"],
963-
)
964-
"""Generate Haskell toolchain libraries.
965-
966-
This is an internal rule and should not be user facing.
967-
968-
This rule is a work-around for toolchain transitions not being implemented,
969-
yet. See
970-
https://github.com/bazelbuild/proposals/blob/master/designs/2019-02-12-toolchain-transitions.md
971-
This will need to be revisited once that proposal is implemented.
972-
"""
973-
974824
def haskell_import_impl(ctx):
975825
# The `allow_files` attribute of `rule` cannot define patterns of accepted
976826
# file extensions like `.so.*`. Instead, we check for the correct file

0 commit comments

Comments
 (0)