@@ -447,6 +447,16 @@ def create_ghc_package(ctx, interfaces_dir, static_library, dynamic_library):
447447 conf_file = ctx .actions .declare_file (paths .join (pkg_db_dir .basename , "{0}.conf" .format (get_pkg_id (ctx ))))
448448 cache_file = ctx .actions .declare_file ("package.cache" , sibling = conf_file )
449449
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+
450460 # Create a file from which ghc-pkg will create the actual package from.
451461 registration_file = ctx .actions .declare_file (target_unique_name (ctx , "registration-file" ))
452462 registration_file_entries = {
@@ -455,8 +465,8 @@ def create_ghc_package(ctx, interfaces_dir, static_library, dynamic_library):
455465 "id" : get_pkg_id (ctx ),
456466 "key" : get_pkg_id (ctx ),
457467 "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 ),
460470 "import-dirs" : paths .join ("${pkgroot}" , interfaces_dir .basename ),
461471 "library-dirs" : "${pkgroot}" ,
462472 "dynamic-library-dirs" : "${pkgroot}" ,
0 commit comments