@@ -447,6 +447,16 @@ def create_ghc_package(ctx, interfaces_dir, static_library, dynamic_library):
447
447
conf_file = ctx .actions .declare_file (paths .join (pkg_db_dir .basename , "{0}.conf" .format (get_pkg_id (ctx ))))
448
448
cache_file = ctx .actions .declare_file ("package.cache" , sibling = conf_file )
449
449
450
+ # Infer collection of public modules in the library.
451
+
452
+ hidden_modules = set .from_list (ctx .attr .hidden_modules )
453
+ public_modules = []
454
+
455
+ for f in _hs_srcs (ctx ):
456
+ mname = module_name (ctx , f )
457
+ if not set .is_member (hidden_modules , mname ):
458
+ public_modules .append (mname )
459
+
450
460
# Create a file from which ghc-pkg will create the actual package from.
451
461
registration_file = ctx .actions .declare_file (target_unique_name (ctx , "registration-file" ))
452
462
registration_file_entries = {
@@ -455,8 +465,8 @@ def create_ghc_package(ctx, interfaces_dir, static_library, dynamic_library):
455
465
"id" : get_pkg_id (ctx ),
456
466
"key" : get_pkg_id (ctx ),
457
467
"exposed" : "True" ,
458
- "exposed-modules" :
459
- " " .join ([ module_name ( ctx , f ) for f in _hs_srcs ( ctx )] ),
468
+ "exposed-modules" : " " . join ( public_modules ),
469
+ "hidden-modules" : " " .join (ctx . attr . hidden_modules ),
460
470
"import-dirs" : paths .join ("${pkgroot}" , interfaces_dir .basename ),
461
471
"library-dirs" : "${pkgroot}" ,
462
472
"dynamic-library-dirs" : "${pkgroot}" ,
0 commit comments