@@ -1307,6 +1307,37 @@ def test_export_all(self):
13071307 self.emcc('lib.c', ['-Oz', '-sEXPORT_ALL', '-sLINKABLE', '--pre-js', 'main.js'], output_filename='a.out.js')
13081308 self.assertContained('libf1\nlibf2\n', self.run_js('a.out.js'))
13091309
1310+ def test_modularize_export_keepalive(self):
1311+ create_file('main.c', r'''
1312+ #include <emscripten.h>
1313+ EMSCRIPTEN_KEEPALIVE int libf1() { return 42; }
1314+ ''')
1315+
1316+ # By default, all kept alive functions should be exported.
1317+ self.emcc('main.c', ['-sMODULARIZE=1'], output_filename='test.js')
1318+
1319+ # print(read_file('test.js'))
1320+
1321+ assert ("Module[\"_libf1\"] = " in read_file('test.js'))
1322+
1323+ # Ensures that EXPORT_KEEPALIVE=0 remove the exports
1324+ self.emcc('main.c', ['-sMODULARIZE=1', '-sEXPORT_KEEPALIVE=0'], output_filename='test.js')
1325+ assert (not ("Module[\"_libf1\"] = " in read_file('test.js')))
1326+
1327+ def test_minimal_modularize_export_keepalive(self):
1328+ create_file('main.c', r'''
1329+ #include <emscripten.h>
1330+ EMSCRIPTEN_KEEPALIVE int libf1() { return 42; }
1331+ ''')
1332+
1333+ # By default, no symbols should be exported when using MINIMAL_RUNTIME.
1334+ self.emcc('main.c', ['-sMODULARIZE=1', '-sMINIMAL_RUNTIME=2'], output_filename='test.js')
1335+ assert (not ("Module[\"_libf1\"] = " in read_file('test.js')))
1336+
1337+ # Ensures that EXPORT_KEEPALIVE=1 exports the symbols.
1338+ self.emcc('main.c', ['-sMODULARIZE=1', '-sMINIMAL_RUNTIME=2', '-sEXPORT_KEEPALIVE'], output_filename='test.js')
1339+ assert ("Module[\"_libf1\"] = " in read_file('test.js'))
1340+
13101341 def test_minimal_runtime_export_all_modularize(self):
13111342 """This test ensures that MODULARIZE and EXPORT_ALL work simultaneously.
13121343
0 commit comments