3
3
load ("@bazel_skylib//lib:paths.bzl" , "paths" )
4
4
load ("@bazel_tools//tools/build_defs/repo:utils.bzl" , "patch" )
5
5
load ("@bazel_tools//tools/cpp:lib_cc_configure.bzl" , "get_cpu_value" )
6
- load ("@rules_sh//sh:posix.bzl" , "sh_posix_configure" )
7
6
load ("@rules_cc//cc:find_cc_toolchain.bzl" , "CC_TOOLCHAIN_TYPE" )
7
+ load ("@rules_sh//sh:posix.bzl" , "sh_posix_configure" )
8
+ load ("//haskell:ghc.bzl" , "DEFAULT_GHC_VERSION" )
9
+ load (":private/bazel_platforms.bzl" , "bazel_platforms" )
8
10
load (
9
11
":private/pkgdb_to_bzl.bzl" ,
10
12
"pkgdb_to_bzl" ,
17
19
"find_python" ,
18
20
"resolve_labels" ,
19
21
)
20
- load ("//haskell:ghc.bzl" , "DEFAULT_GHC_VERSION" )
21
22
22
23
_GHC_DEFAULT_VERSION = DEFAULT_GHC_VERSION
23
24
@@ -86,7 +87,7 @@ def _ghc_bindist_impl(ctx):
86
87
if GHC_BINDIST_STRIP_PREFIX .get (version ) != None and GHC_BINDIST_STRIP_PREFIX [version ].get (target ) != None :
87
88
stripPrefix = GHC_BINDIST_STRIP_PREFIX [version ][target ]
88
89
else :
89
- arch_suffix = {"arm64 " : "aarch64 " , "amd64 " : "x86_64 " }.get (arch )
90
+ arch_suffix = {"amd64 " : "x86_64 " , "arm64 " : "aarch64 " }.get (arch )
90
91
91
92
if os == "windows" and version_tuple >= (9 , 0 , 1 ):
92
93
stripPrefix += "-{}-unknown-mingw32" .format (arch_suffix )
@@ -262,10 +263,10 @@ rm -f
262
263
"BUILD" ,
263
264
filepaths ["@rules_haskell//haskell:ghc.BUILD.tpl" ],
264
265
substitutions = {
265
- "%{toolchain_libraries}" : toolchain_libraries ,
266
- "%{toolchain}" : toolchain ,
267
266
"%{docdir}" : docdir ,
268
267
"%{is_clang}" : str (is_clang ),
268
+ "%{toolchain_libraries}" : toolchain_libraries ,
269
+ "%{toolchain}" : toolchain ,
269
270
},
270
271
executable = False ,
271
272
)
@@ -274,24 +275,11 @@ _ghc_bindist = repository_rule(
274
275
_ghc_bindist_impl ,
275
276
local = False ,
276
277
attrs = {
277
- "version" : attr .string (
278
- default = _GHC_DEFAULT_VERSION ,
279
- doc = "The desired GHC version" ,
280
- ),
281
- "target" : attr .string (),
278
+ "cabalopts" : attr .string_list (),
282
279
"ghcopts" : attr .string_list (),
283
280
"haddock_flags" : attr .string_list (),
284
- "repl_ghci_args" : attr .string_list (),
285
- "cabalopts" : attr .string_list (),
286
- "patches" : attr .label_list (
287
- default = [],
288
- doc =
289
- "A list of files that are to be applied as patches afer " +
290
- "extracting the archive." ,
291
- ),
292
- "patch_tool" : attr .string (
293
- default = "patch" ,
294
- doc = "The patch(1) utility to use." ,
281
+ "locale" : attr .string (
282
+ mandatory = False ,
295
283
),
296
284
"patch_args" : attr .string_list (
297
285
default = ["-p0" ],
@@ -301,8 +289,21 @@ _ghc_bindist = repository_rule(
301
289
default = [],
302
290
doc = "Sequence of commands to be applied after patches are applied." ,
303
291
),
304
- "locale" : attr .string (
305
- mandatory = False ,
292
+ "patch_tool" : attr .string (
293
+ default = "patch" ,
294
+ doc = "The patch(1) utility to use." ,
295
+ ),
296
+ "patches" : attr .label_list (
297
+ default = [],
298
+ doc =
299
+ "A list of files that are to be applied as patches afer " +
300
+ "extracting the archive." ,
301
+ ),
302
+ "repl_ghci_args" : attr .string_list (),
303
+ "target" : attr .string (),
304
+ "version" : attr .string (
305
+ default = _GHC_DEFAULT_VERSION ,
306
+ doc = "The desired GHC version" ,
306
307
),
307
308
"_relpath_script" : attr .label (
308
309
allow_single_file = True ,
@@ -474,7 +475,7 @@ def ghc_bindist(
474
475
"9.2.1" : ["@rules_haskell//haskell:assets/ghc_9_2_1_mac.patch" ],
475
476
}.get (version )
476
477
477
- extra_attrs = {"patches" : patches , " patch_args" : ["-p0" ]} if patches else {}
478
+ extra_attrs = {"patch_args" : ["-p0" ], "patches" : patches } if patches else {}
478
479
479
480
# We want the toolchain definition to be tucked away in a separate
480
481
# repository, that way `bazel build //...` will not match it (and
@@ -567,7 +568,7 @@ def haskell_register_ghc_bindists(
567
568
configure_python3_toolchain (name = LOCAL_PYTHON_REPO_NAME , register = register )
568
569
569
570
def _configure_python3_toolchain_impl (repository_ctx ):
570
- cpu = get_cpu_value (repository_ctx )
571
+ os_cpu = get_cpu_value (repository_ctx )
571
572
python3_path = find_python (repository_ctx )
572
573
if check_bazel_version ("4.2.0" )[0 ]:
573
574
stub_shebang = """stub_shebang = "#!{python3_path}",""" .format (
@@ -595,20 +596,18 @@ toolchain(
595
596
toolchain = ":py_runtime_pair",
596
597
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
597
598
exec_compatible_with = [
598
- "@platforms//cpu:x86_64 ",
599
+ "@platforms//cpu:{cpu} ",
599
600
"@platforms//os:{os}",
600
601
],
601
602
target_compatible_with = [
602
- "@platforms//cpu:x86_64 ",
603
+ "@platforms//cpu:{cpu} ",
603
604
"@platforms//os:{os}",
604
605
],
605
606
)
606
607
""" .format (
607
608
python3 = python3_path ,
608
- os = {
609
- "darwin" : "osx" ,
610
- "x64_windows" : "windows" ,
611
- }.get (cpu , "linux" ),
609
+ os = bazel_platforms .get_os (os_cpu ),
610
+ cpu = bazel_platforms .get_cpu (os_cpu ),
612
611
stub_shebang = stub_shebang ,
613
612
))
614
613
0 commit comments