@@ -338,6 +338,34 @@ GHC_BINDIST = \
338
338
},
339
339
}
340
340
341
+ GHC_BINDIST_STRIP_PREFIX = \
342
+ {
343
+ "9.2.1" : {
344
+ "darwin_amd64" : "ghc-9.2.1-x86_64-apple-darwin" ,
345
+ "windows_amd64" : "ghc-9.2.1-x86_64-unknown-mingw32" ,
346
+ },
347
+ "9.0.1" : {
348
+ "windows_amd64" : "ghc-9.0.1-x86_64-unknown-mingw32" ,
349
+ },
350
+ }
351
+
352
+ GHC_BINDIST_LIBDIR = \
353
+ {
354
+ "9.2.1" : {
355
+ "darwin_amd64" : "lib/lib" ,
356
+ },
357
+ }
358
+
359
+ GHC_BINDIST_DOCDIR = \
360
+ {
361
+ "9.2.1" : {
362
+ "windows_amd64" : "docs" ,
363
+ },
364
+ "9.0.1" : {
365
+ "windows_amd64" : "docs" ,
366
+ },
367
+ }
368
+
341
369
def _ghc_bindist_impl (ctx ):
342
370
filepaths = resolve_labels (ctx , [
343
371
"@rules_haskell//haskell:ghc.BUILD.tpl" ,
@@ -362,12 +390,16 @@ def _ghc_bindist_impl(ctx):
362
390
# the raw distribution.
363
391
unpack_dir = "bindist_unpacked" if os != "windows" else ""
364
392
393
+ stripPrefix = "ghc-" + version
394
+ if GHC_BINDIST_STRIP_PREFIX .get (version ) != None and GHC_BINDIST_STRIP_PREFIX [version ].get (target ) != None :
395
+ stripPrefix = GHC_BINDIST_STRIP_PREFIX [version ][target ]
396
+
365
397
ctx .download_and_extract (
366
398
url = url ,
367
399
output = unpack_dir ,
368
400
sha256 = sha256 ,
369
401
type = "tar.xz" ,
370
- stripPrefix = "ghc-" + version ,
402
+ stripPrefix = stripPrefix ,
371
403
)
372
404
373
405
if os == "windows" :
@@ -411,6 +443,13 @@ def _ghc_bindist_impl(ctx):
411
443
make_loc = ctx .which ("make" )
412
444
if not make_loc :
413
445
fail ("It looks like the build-essential package might be missing, because there is no make in PATH. Are the required dependencies installed? https://rules-haskell.readthedocs.io/en/latest/haskell.html#before-you-begin" )
446
+
447
+ if version == "9.2.1" :
448
+ # Necessary for deterministic builds on macOS. See
449
+ # https://gitlab.haskell.org/ghc/ghc/-/issues/19963
450
+ ctx .file ("{}/mk/relpath.sh" .format (unpack_dir ), ctx .read (ctx .path (ctx .attr ._relpath_script )), executable = False , legacy_utf8 = False )
451
+ execute_or_fail_loudly (ctx , ["chmod" , "+x" , "mk/relpath.sh" ], working_directory = unpack_dir )
452
+
414
453
execute_or_fail_loudly (
415
454
ctx ,
416
455
["make" , "install" ],
@@ -443,7 +482,15 @@ rm -f
443
482
if len (ctx .attr .patches ) > 0 :
444
483
execute_or_fail_loudly (ctx , ["./bin/ghc-pkg" , "recache" ])
445
484
446
- toolchain_libraries = pkgdb_to_bzl (ctx , filepaths , "lib" )
485
+ libdir = "lib"
486
+ if GHC_BINDIST_LIBDIR .get (version ) != None and GHC_BINDIST_LIBDIR [version ].get (target ) != None :
487
+ libdir = GHC_BINDIST_LIBDIR [version ][target ]
488
+
489
+ docdir = "doc"
490
+ if GHC_BINDIST_DOCDIR .get (version ) != None and GHC_BINDIST_DOCDIR [version ].get (target ) != None :
491
+ docdir = GHC_BINDIST_DOCDIR [version ][target ]
492
+
493
+ toolchain_libraries = pkgdb_to_bzl (ctx , filepaths , libdir )
447
494
locale = ctx .attr .locale or ("en_US.UTF-8" if os == "darwin" else "C.UTF-8" )
448
495
toolchain = define_rule (
449
496
"haskell_toolchain" ,
@@ -452,7 +499,7 @@ rm -f
452
499
libraries = "toolchain_libraries" ,
453
500
# See Note [GHC toolchain files]
454
501
libdir = [":lib" ],
455
- docdir = [":doc" ],
502
+ docdir = [":{}" . format ( docdir ) ],
456
503
version = repr (ctx .attr .version ),
457
504
static_runtime = os == "windows" ,
458
505
fully_static_link = False , # XXX not yet supported for bindists.
@@ -468,6 +515,7 @@ rm -f
468
515
substitutions = {
469
516
"%{toolchain_libraries}" : toolchain_libraries ,
470
517
"%{toolchain}" : toolchain ,
518
+ "%{docdir}" : docdir ,
471
519
},
472
520
executable = False ,
473
521
)
@@ -507,6 +555,10 @@ _ghc_bindist = repository_rule(
507
555
"locale" : attr .string (
508
556
mandatory = False ,
509
557
),
558
+ "_relpath_script" : attr .label (
559
+ allow_single_file = True ,
560
+ default = Label ("@rules_haskell//haskell:assets/relpath.sh" ),
561
+ ),
510
562
},
511
563
)
512
564
@@ -604,15 +656,25 @@ def ghc_bindist(
604
656
# Recent GHC versions on Windows contain a bug:
605
657
# https://gitlab.haskell.org/ghc/ghc/issues/16466
606
658
# We work around this by patching the base configuration.
607
- patches = {
608
- "8.6.2" : ["@rules_haskell//haskell:assets/ghc_8_6_2_win_base.patch" ],
609
- "8.6.4" : ["@rules_haskell//haskell:assets/ghc_8_6_4_win_base.patch" ],
610
- "8.6.5" : ["@rules_haskell//haskell:assets/ghc_8_6_5_win_base.patch" ],
611
- "8.8.1" : ["@rules_haskell//haskell:assets/ghc_8_8_1_win_base.patch" ],
612
- "8.8.2" : ["@rules_haskell//haskell:assets/ghc_8_8_2_win_base.patch" ],
613
- "8.8.3" : ["@rules_haskell//haskell:assets/ghc_8_8_3_win_base.patch" ],
614
- "8.8.4" : ["@rules_haskell//haskell:assets/ghc_8_8_4_win_base.patch" ],
615
- }.get (version ) if target == "windows_amd64" else None
659
+ patches = None
660
+ if target == "windows_amd64" :
661
+ patches = {
662
+ "8.6.2" : ["@rules_haskell//haskell:assets/ghc_8_6_2_win_base.patch" ],
663
+ "8.6.4" : ["@rules_haskell//haskell:assets/ghc_8_6_4_win_base.patch" ],
664
+ "8.6.5" : ["@rules_haskell//haskell:assets/ghc_8_6_5_win_base.patch" ],
665
+ "8.8.1" : ["@rules_haskell//haskell:assets/ghc_8_8_1_win_base.patch" ],
666
+ "8.8.2" : ["@rules_haskell//haskell:assets/ghc_8_8_2_win_base.patch" ],
667
+ "8.8.3" : ["@rules_haskell//haskell:assets/ghc_8_8_3_win_base.patch" ],
668
+ "8.8.4" : ["@rules_haskell//haskell:assets/ghc_8_8_4_win_base.patch" ],
669
+ "9.0.1" : ["@rules_haskell//haskell:assets/ghc_9_0_1_win.patch" ],
670
+ "9.2.1" : ["@rules_haskell//haskell:assets/ghc_9_2_1_win.patch" ],
671
+ }.get (version )
672
+
673
+ if target == "darwin_amd64" :
674
+ patches = {
675
+ # Patch for https://gitlab.haskell.org/ghc/ghc/-/issues/19963
676
+ "9.2.1" : ["@rules_haskell//haskell:assets/ghc_9_2_1_mac.patch" ],
677
+ }.get (version )
616
678
617
679
extra_attrs = {"patches" : patches , "patch_args" : ["-p0" ]} if patches else {}
618
680
0 commit comments