Skip to content

Commit

Permalink
Trim set of symbols exported in cantera_shared.dll
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Feb 2, 2023
1 parent 96a1e55 commit 9c05ade
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/SConscript
@@ -1,5 +1,6 @@
from buildutils import *
from pathlib import Path
import re

Import('env', 'build', 'install', 'libraryTargets')

Expand Down Expand Up @@ -128,10 +129,23 @@ localenv.Append(LIBS=localenv['external_libs'],
def create_def_file(target, source, env):
# Adapted from https://stackoverflow.com/a/58958294
startPoint = False
# Exclude standard API like sprintf to avoid multiple definition link error
excluded_functions = {'sprintf', 'snprintf', 'sscanf', 'fprintf'}
# Avoid exporting some unnecessary symbols
exclusions = [
lambda name: name.startswith(('??_G', '??_E')), # deleting destructors; generate warning LNK4102
lambda name: name.startswith(('??_C', '__real@', '__xmm')), # various constants
lambda name: name.startswith(('??$forward', '??$addressof', '??$construct', '??$destroy')),
lambda name: name.startswith(('SUN', 'N_V', 'CV', 'cv', 'IDA', 'ida')), # Sundials
lambda name: '<lambda_' in name, # lambdas
lambda name: '@boost@' in name,
lambda name: ('@Eigen@' in name or '@YAML@' in name) and 'Cantera' not in name,
lambda name: '$vector@' in name and 'Cantera' not in name,
lambda name: 'char_traits' in name and 'Cantera' not in name and 'fmt' not in name,
lambda name: '_Tree' in name or '$_Hash' in name, # standard library internals
lambda name: re.match(r'[\?$]+_[A-Z][a-z_]+@', name), # standard library methods
]

func_count = 0
include_count = 0
with open(target[0].abspath, 'w') as outfile, open(source[0].abspath, 'r') as infile:
outfile.write('EXPORTS\n')

Expand All @@ -142,13 +156,14 @@ def create_def_file(target, source, env):
if not startPoint and "public symbols" in l_str:
startPoint = True
continue
func_count += 1
if startPoint and l_str:
funcName = l_str.split(' ')[-1]
if funcName not in excluded_functions:
func_count += 1
if not any(test(funcName) for test in exclusions):
include_count += 1
outfile.write(" " + funcName + "\n")

logger.info(f"Exported {func_count} functions in .def file")
logger.info(f"Exported {include_count} out of {func_count} functions in .def file")

# Build the Cantera shared library
if localenv['layout'] != 'debian':
Expand All @@ -165,8 +180,7 @@ if localenv['layout'] != 'debian':
dump = localenv.Command('cantera.dump', lib,
'dumpbin /LINKERMEMBER:1 $SOURCE /OUT:$TARGET')
def_file = localenv.Command('cantera_shared.def', dump, create_def_file)
localenv.Append(LINKFLAGS=['/DEF:build/src/cantera_shared.def',
'/IGNORE:4102'])
localenv.Append(LINKFLAGS=['/DEF:build/src/cantera_shared.def'])

if localenv['versioned_shared_library']:
lib = build(localenv.SharedLibrary(sharedName, libraryTargets + sharedIndicator,
Expand Down

0 comments on commit 9c05ade

Please sign in to comment.