Skip to content

Commit

Permalink
[SPEC2DEF] Implement support for debug-only exports
Browse files Browse the repository at this point in the history
  • Loading branch information
tkreuzer committed Jan 18, 2025
1 parent e5830e6 commit ed563ad
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
9 changes: 7 additions & 2 deletions sdk/cmake/gcc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,16 @@ function(fixup_load_config _target)
DEPENDS native-pefixup)
endfunction()

if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR
CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(__spec2def_dbg_arg "--dbg")
endif()

function(generate_import_lib _libname _dllname _spec_file __version_arg)
# Generate the def for the import lib
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def
COMMAND native-spec2def ${__version_arg} -n=${_dllname} -a=${ARCH2} ${ARGN} --implib -d=${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
COMMAND native-spec2def ${__version_arg} ${__spec2def_dbg_arg} -n=${_dllname} -a=${ARCH2} ${ARGN} --implib -d=${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)

# With this, we let DLLTOOL create an import library
Expand Down Expand Up @@ -450,7 +455,7 @@ function(spec2def _dllname _spec_file)
# Generate exports def and C stubs file for the DLL
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c
COMMAND native-spec2def -n=${_dllname} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
COMMAND native-spec2def -n=${_dllname} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${__spec2def_dbg_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)

# Do not use precompiled headers for the stub file
Expand Down
9 changes: 7 additions & 2 deletions sdk/cmake/msvc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ function(fixup_load_config _target)
# msvc knows how to generate a load_config so no hacks here
endfunction()

if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR
CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(__spec2def_dbg_arg "--dbg")
endif()

function(generate_import_lib _libname _dllname _spec_file __version_arg)

set(_def_file ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def)
Expand All @@ -329,7 +334,7 @@ function(generate_import_lib _libname _dllname _spec_file __version_arg)
# Generate the def, asm stub and alias files
add_custom_command(
OUTPUT ${_asm_stubs_file} ${_def_file} ${_asm_impalias_file}
COMMAND native-spec2def --ms ${__version_arg} -a=${SPEC2DEF_ARCH} --implib -n=${_dllname} -d=${_def_file} -l=${_asm_stubs_file} -i=${_asm_impalias_file} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
COMMAND native-spec2def --ms ${__version_arg} ${__spec2def_dbg_arg} -a=${SPEC2DEF_ARCH} --implib -n=${_dllname} -d=${_def_file} -l=${_asm_stubs_file} -i=${_asm_impalias_file} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)

# Compile the generated asm stub file
Expand Down Expand Up @@ -402,7 +407,7 @@ function(spec2def _dllname _spec_file)
# Generate exports def and C stubs file for the DLL
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c
COMMAND native-spec2def --ms -a=${SPEC2DEF_ARCH} -n=${_dllname} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
COMMAND native-spec2def --ms -a=${SPEC2DEF_ARCH} -n=${_dllname} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${__spec2def_dbg_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)

# Do not use precompiled headers for the stub file
Expand Down
13 changes: 13 additions & 0 deletions sdk/tools/spec2def/spec2def.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ int gbImportLib = 0;
int gbNotPrivateNoWarn = 0;
int gbTracing = 0;
int giArch = ARCH_X86;
int gbDbgExports = 0;
char *pszArchString = "i386";
char *pszArchString2;
char *pszSourceFileName = NULL;
Expand Down Expand Up @@ -1162,6 +1163,13 @@ ParseFile(char* pcStart, FILE *fileDest, unsigned *cExports)

} while (*pc == ',');
}
else if (CompareToken(pc, "-dbg"))
{
if (!gbDbgExports)
{
included = 0;
}
}
else if (CompareToken(pc, "-private"))
{
exp.uFlags |= FL_PRIVATE;
Expand Down Expand Up @@ -1505,6 +1513,7 @@ void usage(void)
" -s=<file> generate a stub file\n"
" -i=<file> generate an import alias file\n"
" --ms MSVC compatibility\n"
" --dbg Enable debug exports\n"
" -n=<name> name of the dll\n"
" --version=<version> Sets the version to create exports for\n"
" --implib generate a def file for an import library\n"
Expand Down Expand Up @@ -1571,6 +1580,10 @@ int main(int argc, char *argv[])
{
gbMSComp = 1;
}
else if (strcasecmp(argv[i], "--dbg") == 0)
{
gbDbgExports = 1;
}
else if (strcasecmp(argv[i], "--no-private-warnings") == 0)
{
gbNotPrivateNoWarn = 1;
Expand Down

0 comments on commit ed563ad

Please sign in to comment.