@@ -338,6 +338,34 @@ GHC_BINDIST = \
338338 },
339339 }
340340
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+
341369def _ghc_bindist_impl (ctx ):
342370 filepaths = resolve_labels (ctx , [
343371 "@rules_haskell//haskell:ghc.BUILD.tpl" ,
@@ -362,12 +390,16 @@ def _ghc_bindist_impl(ctx):
362390 # the raw distribution.
363391 unpack_dir = "bindist_unpacked" if os != "windows" else ""
364392
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+
365397 ctx .download_and_extract (
366398 url = url ,
367399 output = unpack_dir ,
368400 sha256 = sha256 ,
369401 type = "tar.xz" ,
370- stripPrefix = "ghc-" + version ,
402+ stripPrefix = stripPrefix ,
371403 )
372404
373405 if os == "windows" :
@@ -411,6 +443,13 @@ def _ghc_bindist_impl(ctx):
411443 make_loc = ctx .which ("make" )
412444 if not make_loc :
413445 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+
414453 execute_or_fail_loudly (
415454 ctx ,
416455 ["make" , "install" ],
@@ -443,7 +482,15 @@ rm -f
443482 if len (ctx .attr .patches ) > 0 :
444483 execute_or_fail_loudly (ctx , ["./bin/ghc-pkg" , "recache" ])
445484
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 )
447494 locale = ctx .attr .locale or ("en_US.UTF-8" if os == "darwin" else "C.UTF-8" )
448495 toolchain = define_rule (
449496 "haskell_toolchain" ,
@@ -452,7 +499,7 @@ rm -f
452499 libraries = "toolchain_libraries" ,
453500 # See Note [GHC toolchain files]
454501 libdir = [":lib" ],
455- docdir = [":doc" ],
502+ docdir = [":{}" . format ( docdir ) ],
456503 version = repr (ctx .attr .version ),
457504 static_runtime = os == "windows" ,
458505 fully_static_link = False , # XXX not yet supported for bindists.
@@ -468,6 +515,7 @@ rm -f
468515 substitutions = {
469516 "%{toolchain_libraries}" : toolchain_libraries ,
470517 "%{toolchain}" : toolchain ,
518+ "%{docdir}" : docdir ,
471519 },
472520 executable = False ,
473521 )
@@ -507,6 +555,10 @@ _ghc_bindist = repository_rule(
507555 "locale" : attr .string (
508556 mandatory = False ,
509557 ),
558+ "_relpath_script" : attr .label (
559+ allow_single_file = True ,
560+ default = Label ("@rules_haskell//haskell:assets/relpath.sh" ),
561+ ),
510562 },
511563)
512564
@@ -604,15 +656,25 @@ def ghc_bindist(
604656 # Recent GHC versions on Windows contain a bug:
605657 # https://gitlab.haskell.org/ghc/ghc/issues/16466
606658 # 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 )
616678
617679 extra_attrs = {"patches" : patches , "patch_args" : ["-p0" ]} if patches else {}
618680
0 commit comments