Skip to content

Commit

Permalink
Strip binaries to reduce size
Browse files Browse the repository at this point in the history
  • Loading branch information
apohl79 committed May 10, 2022
1 parent a1d05c6 commit cd2ab64
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 69 deletions.
61 changes: 54 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,60 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(AG_WITH_SERVER off)
endif()

macro(ag_strip target_name target_dir)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_custom_target(${target_name}_DBGSYM ALL DEPENDS ${target_name}
COMMAND
${CMAKE_COMMAND} -E echo "Creating DWARF file from $<TARGET_FILE:${target_name}>"
COMMAND
${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/debug/${target_dir}
COMMAND
${CMAKE_COMMAND} -E copy $<TARGET_FILE:${target_name}> ${CMAKE_BINARY_DIR}/debug/${target_dir}
COMMAND
/usr/bin/dsymutil -o ${CMAKE_BINARY_DIR}/debug/${target_dir}/$<TARGET_FILE_NAME:${target_name}>.dSYM $<TARGET_FILE:${target_name}>
)
add_custom_target(${target_name}_STRIP ALL DEPENDS ${target_name}_DBGSYM
COMMAND
${CMAKE_COMMAND} -E echo "Stripping file $<TARGET_FILE:${target_name}>"
COMMAND
/usr/bin/strip -S $<TARGET_FILE:${target_name}>
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_custom_target(${target_name}_DBGSYM ALL DEPENDS ${target_name}
COMMAND
${CMAKE_COMMAND} -E echo "Copying debug symbols for $<TARGET_FILE:${target_name}>"
COMMAND
${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/debug/${target_dir}
COMMAND
${CMAKE_COMMAND} -E copy $<TARGET_FILE:${target_name}> ${CMAKE_BINARY_DIR}/debug/${target_dir}
)
add_custom_target(${target_name}_STRIP ALL DEPENDS ${target_name}_DBGSYM
COMMAND
${CMAKE_COMMAND} -E echo "Stripping file $<TARGET_FILE:${target_name}>"
COMMAND
/usr/bin/strip $<TARGET_FILE:${target_name}>
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_custom_target(${target_name}_STRIP ALL DEPENDS ${target_name}
COMMAND
${CMAKE_COMMAND} -E echo "Copying debug symbols for $<TARGET_FILE:${target_name}>"
COMMAND
${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/debug/${target_dir}
COMMAND
${CMAKE_COMMAND} -E copy $<TARGET_FILE:${target_name}> ${CMAKE_BINARY_DIR}/debug/${target_dir}
COMMAND
${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${target_name}> ${CMAKE_BINARY_DIR}/debug/${target_dir}
)
endif()
endmacro()

macro(ag_bundle_add_crashpad target_name)
if(AG_ENABLE_SENTRY)
add_custom_target(${target_name}_CRASHPAD ALL DEPENDS ${target_name}
add_custom_target(${target_name}_CRASHPAD ALL DEPENDS ${target_name}_STRIP
COMMAND
${CMAKE_COMMAND} -E echo "Adding crashpad to bundle $<TARGET_BUNDLE_DIR:${target_name}>"
COMMAND
cp ${CMAKE_BINARY_DIR}/bin/crashpad_handler $<TARGET_BUNDLE_DIR:${target_name}>/Contents/MacOS
${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bin/crashpad_handler $<TARGET_BUNDLE_DIR:${target_name}>/Contents/MacOS
)
else()
add_custom_target(${target_name}_CRASHPAD ALL DEPENDS ${target_name}
Expand All @@ -178,7 +225,7 @@ endmacro()

macro(ag_bundle_sign target_name)
if(AG_ENABLE_CODE_SIGNING)
add_custom_target(${target_name}_SIGN ALL DEPENDS ${target_name}_CRASHPAD
add_custom_target(${target_name}_SIGN ALL DEPENDS ${target_name}_STRIP
COMMAND
${CMAKE_COMMAND} -E echo "Signing bundle $<TARGET_BUNDLE_DIR:${target_name}>"
COMMAND
Expand All @@ -195,14 +242,14 @@ endmacro()
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
macro(ag_bundle_sign_aax target_name)
if(AG_ENABLE_CODE_SIGNING)
add_custom_target(${target_name}_SIGN ALL DEPENDS ${target_name}
add_custom_target(${target_name}_SIGN ALL DEPENDS ${target_name}_STRIP
COMMAND
${CMAKE_COMMAND} -E echo "Signing AAX bundle $<TARGET_BUNDLE_DIR:${target_name}>"
COMMAND
aax_sign.sh $<TARGET_BUNDLE_DIR:${target_name}> || echo "AAX signing not available"
)
else()
add_custom_target(${target_name}_SIGN ALL DEPENDS ${target_name}
add_custom_target(${target_name}_SIGN ALL DEPENDS ${target_name}_STRIP
COMMAND
${CMAKE_COMMAND} -E echo "Code signing disabled. Not signing AAX bundle $<TARGET_BUNDLE_DIR:${target_name}>"
)
Expand All @@ -211,14 +258,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
else()
macro(ag_bundle_sign_aax target_name)
if(AG_ENABLE_CODE_SIGNING)
add_custom_target(${target_name}_SIGN ALL DEPENDS ${target_name}
add_custom_target(${target_name}_SIGN ALL DEPENDS ${target_name}_STRIP
COMMAND
${CMAKE_COMMAND} -E echo "Signing AAX plugin $<TARGET_FILE_NAME:${target_name}>"
COMMAND
aax_sign.bat $<TARGET_FILE:${target_name}>
)
else()
add_custom_target(${target_name}_SIGN ALL DEPENDS ${target_name}
add_custom_target(${target_name}_SIGN ALL DEPENDS ${target_name}_STRIP
COMMAND
${CMAKE_COMMAND} -E echo "Code signing disabled. Not signing AAX plugin $<TARGET_FILE_NAME:${target_name}>"
)
Expand Down
11 changes: 11 additions & 0 deletions Plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,18 @@ macro(ag_add_plugin type)
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags)

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
ag_strip(AudioGridder${type}_AU AU)
endif()

if(AG_VST2_PLUGIN_ENABLED)
ag_strip(AudioGridder${type}_VST VST)
endif()

ag_strip(AudioGridder${type}_VST3 VST3)

if(AG_AAX_PLUGIN_ENABLED)
ag_strip(AudioGridder${type}_AAX AAX)
ag_bundle_sign_aax(AudioGridder${type}_AAX)
endif()

Expand Down
2 changes: 2 additions & 0 deletions PluginTray/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ target_link_libraries(AudioGridderPluginTray PRIVATE
juce::juce_recommended_warning_flags
${SENTRY_LIBRARIES})

ag_strip(AudioGridderPluginTray Tray)

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
ag_bundle_add_crashpad(AudioGridderPluginTray)
ag_bundle_sign(AudioGridderPluginTray)
Expand Down
2 changes: 2 additions & 0 deletions Server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ target_link_libraries(AudioGridderServer PRIVATE
${WEBP_LIBRARIES}
${SENTRY_LIBRARIES})

ag_strip(AudioGridderServer Server)

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_link_libraries(AudioGridderServer PRIVATE "-framework AVFoundation -framework CoreMedia")
if(AG_MACOS_TARGET STRGREATER_EQUAL 10.8)
Expand Down
63 changes: 1 addition & 62 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def getBuildDir(args):
return 'build-' + getPlatformArch(args)

def getDebugSymDir(args):
return 'debug-sym-' + getPlatformArch(args)
return getBuildDir(args) + '/debug'

def getDepsDir(args):
depsDir = args.depsroot
Expand Down Expand Up @@ -246,65 +246,6 @@ def build(args):
cmake_command = 'cmake ' + ' '.join(cmake_params)
execute(cmake_command)

if args.debugsymbols:
debSymDir = getDebugSymDir(args)

log('Creating debug symbols in ' + debSymDir + ' ...')

if os.path.isdir(debSymDir):
shutil.rmtree((debSymDir))

os.mkdir(debSymDir)

if platform == 'macos':
shutil.copytree(buildDir + '/lib', debSymDir + '/lib')
shutil.copytree(buildDir + '/bin', debSymDir + '/bin')
if not os.path.isdir(debSymDir + '/AU'):
os.mkdir(debSymDir + '/AU')
if not os.path.isdir(debSymDir + '/VST'):
os.mkdir(debSymDir + '/VST')
if not os.path.isdir(debSymDir + '/VST3'):
os.mkdir(debSymDir + '/VST3')
if not os.path.isdir(debSymDir + '/AAX'):
os.mkdir(debSymDir + '/AAX')
execute('dsymutil -o ' + debSymDir + '/AudioGridderServer.dSYM ' + buildDir + '/bin/AudioGridderServer.app/Contents/MacOS/AudioGridderServer')
execute('dsymutil -o ' + debSymDir + '/AudioGridderPluginTray.dSYM ' + buildDir + '/bin/AudioGridderPluginTray.app/Contents/MacOS/AudioGridderPluginTray')
execute('dsymutil -o ' + debSymDir + '/AU/AudioGridder.dSYM ' + buildDir + '/lib/AudioGridder.component/Contents/MacOS/AudioGridder')
execute('dsymutil -o ' + debSymDir + '/AU/AudioGridderInst.dSYM ' + buildDir + '/lib/AudioGridderInst.component/Contents/MacOS/AudioGridderInst')
execute('dsymutil -o ' + debSymDir + '/AU/AudioGridderMidi.dSYM ' + buildDir + '/lib/AudioGridderMidi.component/Contents/MacOS/AudioGridderMidi')
execute('dsymutil -o ' + debSymDir + '/VST/AudioGridder.dSYM ' + buildDir + '/lib/AudioGridder.vst/Contents/MacOS/AudioGridder')
execute('dsymutil -o ' + debSymDir + '/VST/AudioGridderInst.dSYM ' + buildDir + '/lib/AudioGridderInst.vst/Contents/MacOS/AudioGridderInst')
execute('dsymutil -o ' + debSymDir + '/VST/AudioGridderMidi.dSYM ' + buildDir + '/lib/AudioGridderMidi.vst/Contents/MacOS/AudioGridderMidi')
execute('dsymutil -o ' + debSymDir + '/VST3/AudioGridder.dSYM ' + buildDir + '/lib/AudioGridder.vst3/Contents/MacOS/AudioGridder')
execute('dsymutil -o ' + debSymDir + '/VST3/AudioGridderInst.dSYM ' + buildDir + '/lib/AudioGridderInst.vst3/Contents/MacOS/AudioGridderInst')
execute('dsymutil -o ' + debSymDir + '/VST3/AudioGridderMidi.dSYM ' + buildDir + '/lib/AudioGridderMidi.vst3/Contents/MacOS/AudioGridderMidi')
execute('dsymutil -o ' + debSymDir + '/AAX/AudioGridder.dSYM ' + buildDir + '/lib/AudioGridder.aaxplugin/Contents/MacOS/AudioGridder')
execute('dsymutil -o ' + debSymDir + '/AAX/AudioGridderInst.dSYM ' + buildDir + '/lib/AudioGridderInst.aaxplugin/Contents/MacOS/AudioGridderInst')
execute('dsymutil -o ' + debSymDir + '/AAX/AudioGridderMidi.dSYM ' + buildDir + '/lib/AudioGridderMidi.aaxplugin/Contents/MacOS/AudioGridderMidi')

elif platform == 'linux':
shutil.copy(buildDir + '/bin/AudioGridderPluginTray', debSymDir)
for f in glob.glob(buildDir + '/lib/*.so'):
shutil.copy(f, debSymDir)

elif platform == "windows":
shutil.copy(buildDir + '/bin/AudioGridderServer.exe', debSymDir)
shutil.copy(buildDir + '/bin/AudioGridderServer.pdb', debSymDir)
shutil.copy(buildDir + '/bin/AudioGridderPluginTray.exe', debSymDir)
shutil.copy(buildDir + '/bin/AudioGridderPluginTray.pdb', debSymDir)
if not os.path.isdir(debSymDir + '/VST'):
os.mkdir(debSymDir + '/VST')
if not os.path.isdir(debSymDir + '/VST3'):
os.mkdir(debSymDir + '/VST3')
if not os.path.isdir(debSymDir + '/AAX'):
os.mkdir(debSymDir + '/AAX')
for f in glob.glob(buildDir + '/lib/VST/*.pdb') + glob.glob(buildDir + '/lib/VST/*.dll'):
shutil.copy(f, debSymDir + '/VST')
for f in glob.glob(buildDir + '/lib/VST3/*.pdb') + glob.glob(buildDir + '/lib/VST3/*.vst3'):
shutil.copy(f, debSymDir + '/VST3')
for f in glob.glob(buildDir + '/lib/AAX/*.pdb') + glob.glob(buildDir + '/lib/AAX/*.aaxplugin'):
shutil.copy(f, debSymDir + '/AAX')

def packs(args):
version = getVersion()
macPackages = []
Expand Down Expand Up @@ -563,8 +504,6 @@ def main():
help='Processor architecture (default: %(default)s)')
parser_build.add_argument('--macos-target', dest='macostarget', metavar='TRGT', type=str, default='10.8',
help='MacOS deplyoment target (default: %(default)s)')
parser_build.add_argument('--create-debug-symbols', dest='debugsymbols', action='store_true', default=False,
help='Create debug symbols for uploading to sentry (default: %(default)s)')
parser_build.add_argument('--target', dest='target', type=str,
help='Set a specific build target')
parser_build.add_argument('-c', '--clean', dest='clean', action='store_true', default=False,
Expand Down

0 comments on commit cd2ab64

Please sign in to comment.