@@ -483,7 +483,7 @@ def _haskell_cabal_library_impl(ctx):
483
483
"_install/{}_data" .format (package_id ),
484
484
sibling = cabal ,
485
485
)
486
- with_haddock = ctx .attr .haddock and hs .tools_config .supports_haddock
486
+ with_haddock = ctx .attr .haddock and hs .tools_config .supports_haddock and not ctx . attr . empty_library
487
487
if with_haddock :
488
488
haddock_file = hs .actions .declare_file (
489
489
"_install/{}_haddock/{}.haddock" .format (package_id , package_name ),
@@ -496,30 +496,36 @@ def _haskell_cabal_library_impl(ctx):
496
496
else :
497
497
haddock_file = None
498
498
haddock_html_dir = None
499
- vanilla_library = hs .actions .declare_file (
500
- "_install/lib/libHS{}.a" .format (package_id ),
501
- sibling = cabal ,
502
- )
503
- if with_profiling :
504
- profiling_library = hs .actions .declare_file (
505
- "_install/lib/libHS{}_p.a" .format (package_id ),
506
- sibling = cabal ,
507
- )
508
- static_library = profiling_library
509
- else :
499
+ if ctx .attr .empty_library :
500
+ vanilla_library = None
501
+ static_library = None
510
502
profiling_library = None
511
- static_library = vanilla_library
512
- if hs .toolchain .static_runtime :
513
503
dynamic_library = None
514
504
else :
515
- dynamic_library = hs .actions .declare_file (
516
- "_install/lib/libHS{}-ghc{}.{}" .format (
517
- package_id ,
518
- hs .toolchain .version ,
519
- _so_extension (hs ),
520
- ),
505
+ vanilla_library = hs .actions .declare_file (
506
+ "_install/lib/libHS{}.a" .format (package_id ),
521
507
sibling = cabal ,
522
508
)
509
+ if with_profiling :
510
+ profiling_library = hs .actions .declare_file (
511
+ "_install/lib/libHS{}_p.a" .format (package_id ),
512
+ sibling = cabal ,
513
+ )
514
+ static_library = profiling_library
515
+ else :
516
+ profiling_library = None
517
+ static_library = vanilla_library
518
+ if hs .toolchain .static_runtime :
519
+ dynamic_library = None
520
+ else :
521
+ dynamic_library = hs .actions .declare_file (
522
+ "_install/lib/libHS{}-ghc{}.{}" .format (
523
+ package_id ,
524
+ hs .toolchain .version ,
525
+ _so_extension (hs ),
526
+ ),
527
+ sibling = cabal ,
528
+ )
523
529
(tool_inputs , tool_input_manifests ) = ctx .resolve_tools (tools = ctx .attr .tools )
524
530
c = _prepare_cabal_inputs (
525
531
hs ,
@@ -553,11 +559,12 @@ def _haskell_cabal_library_impl(ctx):
553
559
outputs = [
554
560
package_database ,
555
561
interfaces_dir ,
556
- vanilla_library ,
557
562
data_dir ,
558
563
]
559
564
if with_haddock :
560
565
outputs .extend ([haddock_file , haddock_html_dir ])
566
+ if vanilla_library != None :
567
+ outputs .append (vanilla_library )
561
568
if dynamic_library != None :
562
569
outputs .append (dynamic_library )
563
570
if with_profiling :
@@ -578,8 +585,13 @@ def _haskell_cabal_library_impl(ctx):
578
585
progress_message = "HaskellCabalLibrary {}" .format (hs .label ),
579
586
)
580
587
588
+ if not ctx .attr .empty_library :
589
+ default_info_libs = depset ([static_library ] + ([dynamic_library ] if dynamic_library != None else []))
590
+ else :
591
+ default_info_libs = depset ([package_database ])
592
+
581
593
default_info = DefaultInfo (
582
- files = depset ([ static_library ] + ([ dynamic_library ] if dynamic_library != None else [])) ,
594
+ files = default_info_libs ,
583
595
runfiles = ctx .runfiles (
584
596
files = [data_dir ],
585
597
collect_default = True ,
@@ -628,7 +640,7 @@ def _haskell_cabal_library_impl(ctx):
628
640
)
629
641
linker_input = cc_common .create_linker_input (
630
642
owner = ctx .label ,
631
- libraries = depset (direct = [
643
+ libraries = depset (direct = ([] if ctx . attr . empty_library else [
632
644
cc_common .create_library_to_link (
633
645
actions = ctx .actions ,
634
646
feature_configuration = feature_configuration ,
@@ -638,7 +650,7 @@ def _haskell_cabal_library_impl(ctx):
638
650
static_library = static_library ,
639
651
cc_toolchain = cc_toolchain ,
640
652
),
641
- ]),
653
+ ])) ,
642
654
)
643
655
compilation_context = cc_common .create_compilation_context ()
644
656
linking_context = cc_common .create_linking_context (
@@ -747,6 +759,11 @@ haskell_cabal_library = rule(
747
759
library symlink underneath `_solib_<cpu>` will be shortened to
748
760
avoid exceeding the MACH-O header size limit on MacOS.""" ,
749
761
),
762
+ "empty_library" : attr .bool (
763
+ default = False ,
764
+ doc = """Whether the main cabal library is empty and merely re-exports from other sub libraries.
765
+ It is necessary to set this, otherwise bazel will complain about missing "*libHS.a" files.""" ,
766
+ ),
750
767
},
751
768
toolchains = use_cc_toolchain () + [
752
769
"@rules_haskell//haskell:toolchain" ,
0 commit comments