Skip to content

Commit a2d7410

Browse files
committed
Remove calls to resolve_tools
Replace them mostly with `FilesToRunProvider`s. For cc_wrapper, where repl's also need the runfiles, use a struct that has the executable, the `FilesToRunProvider` and the runfiles. The executable could be retrieved from the `FilesToRunProvider`, but it is more convenient to just have it in the struct. Remove outdated comment about re-enabling resolve_tools for bazel 8
1 parent 929d6f6 commit a2d7410

18 files changed

Lines changed: 126 additions & 193 deletions

File tree

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ You'll need [Bazel >= 6.0][bazel-getting-started] installed.
2727

2828
If you are on NixOS, skip to the [Nixpkgs](#Nixpkgs) section.
2929

30-
> [!NOTE]
31-
> Bazel 8 users will need to add
32-
> `common --noincompatible_disallow_ctx_resolve_tools` to `.bazelrc`
33-
3430
### System dependencies
3531

3632
Refer to the "Before you begin" section in [the documentation](docs/haskell.rst).

haskell/c2hs.bzl

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def _c2hs_library_impl(ctx):
3131
)
3232
args = hs.actions.args()
3333
c2hs = ctx.toolchains["@rules_haskell//haskell/c2hs:toolchain"].c2hs
34-
c2hs_exe = ctx.toolchains["@rules_haskell//haskell/c2hs:toolchain"].c2hs_exe
3534

3635
if len(ctx.files.srcs) != 1:
3736
fail("srcs field should contain exactly one file.")
@@ -44,7 +43,7 @@ def _c2hs_library_impl(ctx):
4443
args.add_all([chs_file.path, "-o", hs_file.path])
4544

4645
args.add("-C-E")
47-
args.add_all(["--cpp", cc.tools.cc])
46+
args.add_all(["--cpp", cc.tools.cc.executable.path])
4847
args.add("-C-includeghcplatform.h")
4948
args.add("-C-includeghcversion.h")
5049
args.add_all(["-C" + x for x in cc.cpp_flags])
@@ -70,21 +69,16 @@ def _c2hs_library_impl(ctx):
7069
(version_macro_headers, version_macro_flags) = version_macro_includes(dep_info)
7170
args.add_all(["-C" + x for x in version_macro_flags])
7271

73-
(inputs, input_manifests) = ctx.resolve_tools(tools = [c2hs])
74-
7572
hs.actions.run_shell(
7673
inputs = depset(transitive = [
7774
depset(cc.hdrs),
7875
depset([chs_file]),
7976
depset(dep_chi_files),
80-
depset(cc.files),
8177
depset(hs.toolchain.bindir),
8278
depset(hs.toolchain.libdir),
8379
set.to_depset(version_macro_headers),
84-
inputs,
8580
]),
86-
input_manifests = input_manifests,
87-
tools = [hs.tools.ghc_pkg, c2hs_exe],
81+
tools = [hs.tools.ghc_pkg, c2hs, cc.tools.cc.as_tool],
8882
outputs = [hs_file, chi_file],
8983
command =
9084
# cpp (called via c2hs) gets very unhappy if the mingw bin dir is
@@ -103,7 +97,7 @@ def _c2hs_library_impl(ctx):
10397
{c2hs} "${{include_dirs_args[@]}}" "$@"
10498
""".format(
10599
ghc_pkg = hs.tools.ghc_pkg.path,
106-
c2hs = c2hs_exe.path,
100+
c2hs = c2hs.executable.path,
107101
),
108102
mnemonic = "HaskellC2Hs",
109103
arguments = [args],
@@ -159,12 +153,10 @@ def _c2hs_toolchain_impl(ctx):
159153
return [
160154
platform_common.ToolchainInfo(
161155
name = ctx.label.name,
162-
# We have both c2hs which points to the target and c2hs_exe
163-
# which points to the file. The former is used to collect
164-
# runfiles while the latter is used to get the path to
165-
# c2hs.
166-
c2hs = ctx.attr.c2hs,
167-
c2hs_exe = ctx.executable.c2hs,
156+
# Get a FilesToRunProvider which can be used to insert all the
157+
# necessary files for the tool into the environment of an action
158+
# run.
159+
c2hs = ctx.attr.c2hs[DefaultInfo].files_to_run,
168160
),
169161
]
170162

haskell/cabal.bzl

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def _cabal_toolchain_info(hs, cc, workspace_name, runghc):
161161
hsc2hs = hs.tools.hsc2hs.path,
162162
runghc = runghc.path,
163163
ar = ar,
164-
cc = cc.tools.cc,
164+
cc = cc.tools.cc.executable.path,
165165
ld = cc.tools.ld,
166166
strip = cc.tools.strip,
167167
is_windows = hs.toolchain.is_windows,
@@ -179,8 +179,6 @@ def _prepare_cabal_inputs(
179179
direct_cc_info,
180180
component,
181181
package_id,
182-
tool_inputs,
183-
tool_input_manifests,
184182
cabal,
185183
setup,
186184
setup_deps,
@@ -252,7 +250,7 @@ def _prepare_cabal_inputs(
252250
env = dicts.add(hs.env, cc.env)
253251
env["PATH"] = join_path_list(
254252
hs.toolchain.is_windows,
255-
_binary_paths(tool_inputs) + posix.paths + hs.tools_config.path_for_cabal,
253+
posix.paths + hs.tools_config.path_for_cabal,
256254
)
257255
if hs.toolchain.is_darwin:
258256
env["SDKROOT"] = "macosx" # See haskell/private/actions/link.bzl
@@ -348,7 +346,6 @@ def _prepare_cabal_inputs(
348346
extra_ldflags_file = darwin_flags_for_linking_indirect_cc_deps(hs, cc, posix, hs.name, dynamic = True)
349347

350348
# Redundant with _binary_paths() above, but better be explicit when we can.
351-
path_args.extend([_cabal_tool_flag(tool_flag) for tool_flag in tool_inputs.to_list() if _cabal_tool_flag(tool_flag)])
352349

353350
repo_name = "_main"
354351
if generate_paths_module and label and label.repo_name:
@@ -389,7 +386,6 @@ def _prepare_cabal_inputs(
389386
input_files,
390387
transitive = [
391388
depset(srcs),
392-
depset(cc.files),
393389
depset(ghc_files),
394390
package_databases,
395391
setup_dep_info.package_databases,
@@ -402,18 +398,14 @@ def _prepare_cabal_inputs(
402398
setup_dep_info.hs_libraries,
403399
dep_info.interface_dirs,
404400
dep_info.hs_libraries,
405-
tool_inputs,
406401
],
407402
)
408-
input_manifests = tool_input_manifests + hs.toolchain.cc_wrapper.manifests
409-
410403
runfiles_direct = runfiles_libs if static_binary else dynamic_libs
411404

412405
return struct(
413406
cabal_wrapper = cabal_wrapper,
414407
args = args,
415408
inputs = inputs,
416-
input_manifests = input_manifests,
417409
env = env,
418410
runfiles = depset(direct = runfiles_direct),
419411
)
@@ -575,7 +567,7 @@ def _haskell_cabal_library_impl(ctx):
575567
),
576568
sibling = cabal,
577569
)
578-
(tool_inputs, tool_input_manifests) = ctx.resolve_tools(tools = ctx.attr.tools)
570+
attr_tools = [tool[DefaultInfo].files_to_run for tool in ctx.attr.tools]
579571
c = _prepare_cabal_inputs(
580572
hs,
581573
cc,
@@ -586,8 +578,6 @@ def _haskell_cabal_library_impl(ctx):
586578
direct_cc_info,
587579
component = "lib:{}".format(ctx.attr.sublibrary_name or ctx.attr.package_name or hs.label.name),
588580
package_id = package_id,
589-
tool_inputs = tool_inputs,
590-
tool_input_manifests = tool_input_manifests,
591581
cabal = cabal,
592582
setup = setup,
593583
setup_deps = setup_deps,
@@ -620,15 +610,23 @@ def _haskell_cabal_library_impl(ctx):
620610
if with_profiling:
621611
outputs.append(profiling_library)
622612

623-
(_, runghc_manifest) = ctx.resolve_tools(tools = [ctx.attr._runghc])
624613
json_args = ctx.actions.declare_file("{}_cabal_wrapper_args.json".format(ctx.label.name))
625614
ctx.actions.write(json_args, json.encode(c.args))
615+
616+
# Ensure that dependent tools can be found.
617+
paths = []
618+
if "PATH" in c.env:
619+
paths.append(c.env["PATH"])
620+
paths.extend([t.executable.dirname for t in attr_tools])
621+
c.env["PATH"] = ":".join(paths)
622+
626623
ctx.actions.run(
627624
executable = c.cabal_wrapper,
628625
arguments = [json_args.path],
629626
inputs = depset([json_args], transitive = [c.inputs]),
630-
input_manifests = c.input_manifests + runghc_manifest,
631-
tools = [c.cabal_wrapper, ctx.executable._runghc] + hs.tools_config.tools_for_ghc,
627+
tools = attr_tools +
628+
[c.cabal_wrapper, ctx.executable._runghc, hs.toolchain.cc_wrapper.as_tool] +
629+
hs.tools_config.tools_for_ghc,
632630
outputs = outputs,
633631
env = c.env,
634632
mnemonic = "HaskellCabalLibrary",
@@ -911,7 +909,7 @@ def _haskell_cabal_binary_impl(ctx):
911909
"_install/{}_data".format(hs.label.name),
912910
sibling = cabal,
913911
)
914-
(tool_inputs, tool_input_manifests) = ctx.resolve_tools(tools = ctx.attr.tools)
912+
attr_tools = [tool[DefaultInfo].files_to_run for tool in ctx.attr.tools]
915913
c = _prepare_cabal_inputs(
916914
hs,
917915
cc,
@@ -922,8 +920,6 @@ def _haskell_cabal_binary_impl(ctx):
922920
direct_cc_info,
923921
component = "exe:{}".format(exe_name),
924922
package_id = hs.label.name,
925-
tool_inputs = tool_inputs,
926-
tool_input_manifests = tool_input_manifests,
927923
cabal = cabal,
928924
setup = setup,
929925
setup_deps = setup_deps,
@@ -942,20 +938,20 @@ def _haskell_cabal_binary_impl(ctx):
942938
static_binary = static_binary,
943939
label = ctx.label,
944940
)
945-
(_, runghc_manifest) = ctx.resolve_tools(tools = [ctx.attr._runghc])
946941
json_args = ctx.actions.declare_file("{}_cabal_wrapper_args.json".format(ctx.label.name))
947942
ctx.actions.write(json_args, json.encode(c.args))
948943
ctx.actions.run(
949944
executable = c.cabal_wrapper,
950945
arguments = [json_args.path],
951946
inputs = depset([json_args], transitive = [c.inputs]),
952-
input_manifests = c.input_manifests + runghc_manifest,
953947
outputs = [
954948
package_database,
955949
binary,
956950
data_dir,
957951
],
958-
tools = [c.cabal_wrapper, ctx.executable._runghc] + hs.tools_config.tools_for_ghc,
952+
tools = attr_tools +
953+
[c.cabal_wrapper, ctx.executable._runghc, hs.toolchain.cc_wrapper.as_tool] +
954+
hs.tools_config.tools_for_ghc,
959955
env = c.env,
960956
mnemonic = "HaskellCabalBinary",
961957
progress_message = "HaskellCabalBinary {}".format(hs.label),

haskell/cc.bzl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,10 @@ def cc_interop_info(ctx, override_cc_toolchain = None):
118118
# Generate cc wrapper script on Darwin that adjusts load commands.
119119
hs_toolchain = ctx.toolchains["@rules_haskell//haskell:toolchain"]
120120
cc_wrapper = hs_toolchain.cc_wrapper
121-
cc = cc_wrapper.executable.path
122-
cc_files = depset(transitive = [cc_toolchain.all_files, cc_wrapper.inputs])
123-
cc_manifests = cc_wrapper.manifests
124121

125122
tools = {
126123
"ar": cc_toolchain.ar_executable,
127-
"cc": cc,
124+
"cc": cc_wrapper,
128125
"ld": cc_toolchain.ld_executable,
129126
"cpp": cc_toolchain.preprocessor_executable,
130127
"nm": cc_toolchain.nm_executable,
@@ -163,8 +160,6 @@ def cc_interop_info(ctx, override_cc_toolchain = None):
163160
return CcInteropInfo(
164161
tools = struct(**tools),
165162
env = env,
166-
files = cc_files.to_list(),
167-
manifests = cc_manifests,
168163
hdrs = hdrs.to_list(),
169164
cpp_flags = cpp_flags,
170165
include_args = include_args,

haskell/doctest.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _haskell_doctest_single(target, ctx):
9898
ctx,
9999
override_cc_toolchain = hs.tools_config.maybe_exec_cc_toolchain,
100100
)
101-
args.add_all(ghc_cc_program_args(hs, cc.tools.cc, cc.tools.ld))
101+
args.add_all(ghc_cc_program_args(hs, cc.tools.cc.executable.path, cc.tools.ld))
102102

103103
doctest_log = ctx.actions.declare_file(
104104
"doctest-log-" + ctx.label.name + "-" + target.label.name,
@@ -137,7 +137,6 @@ def _haskell_doctest_single(target, ctx):
137137
depset(get_ghci_library_files(hs, cc_libraries_info, cc.transitive_libraries)),
138138
depset(
139139
toolchain.doctest +
140-
cc.files +
141140
[hs.tools.ghc],
142141
),
143142
]),
@@ -173,6 +172,7 @@ def _haskell_doctest_single(target, ctx):
173172
# sandboxing altogether for doctest tests.
174173
"no-sandbox": "1",
175174
},
175+
tools = [cc.tools.cc.as_tool],
176176
)
177177
return doctest_log
178178

haskell/experimental/private/module.bzl

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ load(
2121
)
2222
load("//haskell:private/path_utils.bzl", "infer_main_module")
2323
load("//haskell:private/pkg_id.bzl", "pkg_id")
24-
load(
25-
"//haskell:private/plugins.bzl",
26-
"resolve_plugin_tools",
27-
)
2824
load(
2925
"//haskell:providers.bzl",
3026
"GhcPluginInfo",
@@ -173,8 +169,9 @@ def _build_haskell_module(
173169
module_attr.name,
174170
[dep for plugin in plugin_decl for dep in plugin[GhcPluginInfo].deps],
175171
)
176-
plugins = [resolve_plugin_tools(ctx, plugin[GhcPluginInfo]) for plugin in plugin_decl]
177-
(preprocessors_inputs, preprocessors_input_manifests) = ctx.resolve_tools(tools = ctx.attr.tools + module_attr.tools)
172+
plugin_infos = [plugin[GhcPluginInfo] for plugin in plugin_decl]
173+
plugin_tools = [tool[DefaultInfo].files_to_run for i in plugin_infos for tool in i.tools]
174+
attr_tools = [tool[DefaultInfo].files_to_run for tool in (ctx.attr.tools + module_attr.tools)]
178175

179176
# TODO[AH] Support additional outputs such as `.hie`.
180177

@@ -254,7 +251,7 @@ def _build_haskell_module(
254251

255252
args.add_all(cc.include_args)
256253

257-
if plugins or enable_th:
254+
if plugin_infos or enable_th:
258255
# cc toolchain linker flags would be necessary when the interpreter wants to
259256
# load any libraries
260257
args.add_all(cc.linker_flags, format_each = "-optl%s")
@@ -278,8 +275,8 @@ def _build_haskell_module(
278275
plugin_pkg_info = expose_packages(
279276
package_ids = [
280277
pkg_id
281-
for plugin in plugins
282-
for pkg_id in all_dependencies_package_ids(plugin.deps)
278+
for plugin_info in plugin_infos
279+
for pkg_id in all_dependencies_package_ids(plugin_info.deps)
283280
],
284281
package_databases = plugin_dep_info.package_databases,
285282
version = version,
@@ -288,17 +285,10 @@ def _build_haskell_module(
288285
)
289286
args.add_all(pkg_info_args)
290287

291-
for plugin in plugins:
292-
args.add("-fplugin={}".format(plugin.module))
293-
for opt in plugin.args:
294-
args.add_all(["-fplugin-opt", "{}:{}".format(plugin.module, opt)])
295-
296-
plugin_tool_inputs = depset(transitive = [plugin.tool_inputs for plugin in plugins])
297-
plugin_tool_input_manifests = [
298-
manifest
299-
for plugin in plugins
300-
for manifest in plugin.tool_input_manifests
301-
]
288+
for plugin_info in plugin_infos:
289+
args.add("-fplugin={}".format(plugin_info.module))
290+
for opt in plugin_info.args:
291+
args.add_all(["-fplugin-opt", "{}:{}".format(plugin_info.module, opt)])
302292

303293
args.add_all(hs.toolchain.ghcopts)
304294
args.add_all(user_ghcopts)
@@ -310,7 +300,7 @@ def _build_haskell_module(
310300
args.add(paths.join(ar_bindir, "otool"), format = "-pgmotool=%s")
311301
args.add(paths.join(ar_bindir, "install_name_tool"), format = "-pgminstall_name_tool=%s")
312302

313-
if plugins and not enable_th:
303+
if plugin_infos and not enable_th:
314304
# For #1681. These suppresses bogus warnings about missing libraries which
315305
# aren't really needed.
316306
args.add("-Wno-missed-extra-shared-lib")
@@ -345,8 +335,6 @@ def _build_haskell_module(
345335
plugin_dep_info.package_databases,
346336
plugin_dep_info.interface_dirs,
347337
plugin_dep_info.hs_libraries,
348-
plugin_tool_inputs,
349-
preprocessors_inputs,
350338
interface_inputs,
351339
abi_inputs,
352340
] + [
@@ -361,7 +349,6 @@ def _build_haskell_module(
361349
if enable_th
362350
],
363351
),
364-
input_manifests = preprocessors_input_manifests + plugin_tool_input_manifests,
365352
outputs = outputs,
366353
mnemonic = "HaskellBuildObject" + ("Prof" if with_profiling else ""),
367354
progress_message = "HaskellBuildObject {} {}".format(hs.label, module.label),
@@ -371,6 +358,7 @@ def _build_haskell_module(
371358
extra_name = module.label.package.replace("/", "_") + "_" + module.label.name,
372359
hi_file = module_outputs.hi,
373360
abi_file = module_outputs.abi,
361+
extra_tools = attr_tools + plugin_tools,
374362
)
375363

376364
is_boot = _is_boot(src.path)

0 commit comments

Comments
 (0)