Skip to content

Commit

Permalink
Improved MSVCRT build scripts, Only _allmul, proper testing and a c…
Browse files Browse the repository at this point in the history
…leanup remains

Update CMakeLists.txt, build-msvc-internal.cmd, and 4 more files...
  • Loading branch information
aziascreations committed Jul 18, 2024
1 parent 6748111 commit 3c0f8fb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ if(NP_GOODIES_IS_MAIN)

# Targets > Dummy > MSVCRT Headers
if(WIN32)
file(GLOB_RECURSE src_msvcrt_dummy CONFIGURE_DEPENDS "msvcrt/main.cmakesilencer.c" "msvcrt/src/*.h" "msvcrt/src/*.c")
file(GLOB_RECURSE src_msvcrt_dummy CONFIGURE_DEPENDS "msvcrt/main.cmakesilencer.c" "msvcrt/headers/*.h" "msvcrt/headers/*.c")
add_library(np_clang_goodies_msvcrt_dummy STATIC ${src_msvcrt_dummy})
endif()
else()
Expand Down
20 changes: 13 additions & 7 deletions build-msvc-internal.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ set _RSC_DIR=%6
set _RSC_DIR=%_RSC_DIR:"=%
set _CC_FLAGS=%7
set _CC_FLAGS=%_CC_FLAGS:"=%
set _LINK_FLAGS=%8
set _LINK_FLAGS=%_LINK_FLAGS:"=%
set _LINK_FLAGS_DLL=%8
set _LINK_FLAGS_DLL=%_LINK_FLAGS_DLL:"=%
set _LINK_FLAGS_EXE=%9
set _LINK_FLAGS_EXE=%_LINK_FLAGS_EXE:"=%

echo ^> _VCVARS_BATCH=%_VCVARS_BATCH%
echo ^> _BUILD_DIR=%_BUILD_DIR%
echo ^> _SRC_DIR=%_SRC_DIR%
echo ^> _BENCHMARK_DIR=%_BENCHMARK_DIR%
echo ^> _EXAMPLES_DIR=%_EXAMPLES_DIR%
echo ^> _RSC_DIR=%_RSC_DIR%
echo ^> _CC_FLAGS=%_CC_FLAGS%
echo ^> _LINK_FLAGS=%_LINK_FLAGS%
echo ^> _LINK_FLAGS_DLL=%_LINK_FLAGS_DLL%
echo ^> _LINK_FLAGS_EXE=%_LINK_FLAGS_EXE%

:: Calling the given VS script to get 'CL' and 'LINK' in the PATH
echo Setting up VS environment
Expand Down Expand Up @@ -99,6 +103,7 @@ cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\lists\common
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\uuid\uuid.o" -c "%_SRC_DIR%\uuid\uuid.c"
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\uuid\uuid4.o" -c "%_SRC_DIR%\uuid\uuid4.c"
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\text.o" -c "%_SRC_DIR%\text.c"
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\_win32_main.o" -c "%_SRC_DIR%\_win32_main.c"
rc /nologo /fo "%_OBJ_DIR%\dll_dynamic\np_clang_goodies.res" "%_RSC_DIR%\np_clang_goodies.rc"
set _DLL_OBJS=
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\arguments\arguments.o"
Expand All @@ -112,20 +117,21 @@ set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\lists\commons.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\uuid\uuid.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\uuid\uuid4.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\text.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\_win32_main.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\np_clang_goodies.res"
link %_LINK_FLAGS% /DLL %_DLL_OBJS% /out:%_BIN_DIR%\dll_dynamic\np_clang_goodies.dll
link %_LINK_FLAGS_DLL% /DLL %_DLL_OBJS% /out:%_BIN_DIR%\dll_dynamic\np_clang_goodies.dll


echo Benchmarks
echo Benchmark ^> CRC32 Implementations
cl %_CC_FLAGS% /Fo: "%_OBJ_DIR%\bm_crc32_implementations.o" -c "%_BENCHMARK_DIR%\bm_crc32_implementations.c"
link %_LINK_FLAGS% "%_OBJ_DIR%\bm_crc32_implementations.o" /out:%_BIN_DIR%\bm_crc32_implementations.exe
link %_LINK_FLAGS_EXE% "%_OBJ_DIR%\bm_crc32_implementations.o" /out:%_BIN_DIR%\bm_crc32_implementations.exe
echo Benchmark ^> Binary Powers
cl %_CC_FLAGS% /Fo: "%_OBJ_DIR%\bm_powers_of_two.o" -c "%_BENCHMARK_DIR%\bm_powers_of_two.c"
link %_LINK_FLAGS% "%_OBJ_DIR%\bm_powers_of_two.o" /out:%_BIN_DIR%\bm_powers_of_two.exe
link %_LINK_FLAGS_EXE% "%_OBJ_DIR%\bm_powers_of_two.o" /out:%_BIN_DIR%\bm_powers_of_two.exe
echo Benchmark ^> Binary Roots
cl %_CC_FLAGS% /Fo: "%_OBJ_DIR%\bm_square_of_two_mask.o" -c "%_BENCHMARK_DIR%\bm_square_of_two_mask.c"
link %_LINK_FLAGS% "%_OBJ_DIR%\bm_square_of_two_mask.o" /out:%_BIN_DIR%\bm_square_of_two_mask.exe
link %_LINK_FLAGS_EXE% "%_OBJ_DIR%\bm_square_of_two_mask.o" /out:%_BIN_DIR%\bm_square_of_two_mask.exe


:: Going back to the original directory
Expand Down
17 changes: 12 additions & 5 deletions build-msvc.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ set BENCHMARK_DIR=%~dp0\benchmarks
set EXAMPLES_DIR=%~dp0\examples
set SRC_DIR=%~dp0\src
set RSC_DIR=%~dp0\rsc
set MSVCRT_DIR=%~dp0\msvcrt\src
set MSVCRT_HEADER_DIR=%~dp0\msvcrt\headers
set MSVCRT_LIB_DIR=%~dp0\msvcrt\libs


:: Checking the to make sure you ain't running of a VS console
Expand Down Expand Up @@ -62,6 +63,7 @@ echo ========================================
call build-msvc-internal.cmd "%VCVARS_ROOT%\vcvars64.bat" "%BUILD_DIR%\x64-ucrt" "%SRC_DIR%" ^
"%BENCHMARK_DIR%" "%EXAMPLES_DIR%" "%RSC_DIR%" ^
"%FLAGS_CC%" ^
"%FLAGS_LINK%" ^
"%FLAGS_LINK%"
echo.

Expand All @@ -71,8 +73,9 @@ echo C99 Goodies - x64 MSVCRT Build
echo ========================================
call build-msvc-internal.cmd "%VCVARS_ROOT%\vcvars64.bat" "%BUILD_DIR%\x64-msvcrt" "%SRC_DIR%" ^
"%BENCHMARK_DIR%" "%EXAMPLES_DIR%" "%RSC_DIR%" ^
"%FLAGS_MSVCRT_CC% /external:W4 /external:I ""%MSVCRT_DIR%""" ^
"%FLAGS_MSVCRT_LINK% /NODEFAULTLIB user32.lib kernel32.lib ^"%RSC_DIR%\libs\x64\msvcrt.lib^""
"%FLAGS_MSVCRT_CC% /external:W4 /external:I ""%MSVCRT_HEADER_DIR%""" ^
"%FLAGS_MSVCRT_LINK% /ENTRY:DllMain /NODEFAULTLIB user32.lib kernel32.lib ""%MSVCRT_LIB_DIR%\x64\win11-23h2-pro_msdn-iso\System32\msvcrt.lib""" ^
"%FLAGS_MSVCRT_LINK% /ENTRY:main /NODEFAULTLIB user32.lib kernel32.lib ""%MSVCRT_LIB_DIR%\x64\win11-23h2-pro_msdn-iso\System32\msvcrt.lib"""
echo.

:build-x86-ucrt
Expand All @@ -81,6 +84,7 @@ echo ========================================
call build-msvc-internal.cmd "%VCVARS_ROOT%\vcvars32.bat" "%BUILD_DIR%\x86-ucrt" "%SRC_DIR%" ^
"%BENCHMARK_DIR%" "%EXAMPLES_DIR%" "%RSC_DIR%" ^
"%FLAGS_CC%" ^
"%FLAGS_LINK%" ^
"%FLAGS_LINK%"
echo.

Expand All @@ -89,8 +93,11 @@ echo C99 Goodies - x86 MSVCRT Build
echo ========================================
call build-msvc-internal.cmd "%VCVARS_ROOT%\vcvars32.bat" "%BUILD_DIR%\x86-msvcrt" "%SRC_DIR%" ^
"%BENCHMARK_DIR%" "%EXAMPLES_DIR%" "%RSC_DIR%" ^
"%FLAGS_MSVCRT_CC% /external:W4 /external:I ""%MSVCRT_DIR%""" ^
"%FLAGS_MSVCRT_LINK% /NODEFAULTLIB user32.lib kernel32.lib ^"%RSC_DIR%\libs\x86\msvcrt.lib^""
"%FLAGS_MSVCRT_CC% /external:W4 /external:I ""%MSVCRT_HEADER_DIR%""" ^
"%FLAGS_MSVCRT_LINK% /ENTRY:DllMain /NODEFAULTLIB user32.lib kernel32.lib ""%MSVCRT_LIB_DIR%\x86\win11-23h2-pro_msdn-iso_x64\SysWOW64\msvcrt.lib""" ^
"%FLAGS_MSVCRT_LINK% /ENTRY:main /NODEFAULTLIB user32.lib kernel32.lib ""%MSVCRT_LIB_DIR%\x86\win11-23h2-pro_msdn-iso_x64\SysWOW64\msvcrt.lib"""
:: https://yal.cc/cpp-a-very-tiny-dll/
:: ___allmul => _allmul => ntdll.lib
echo.


Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions msvcrt/headers/wchar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <stddef.h>

#define WCHAR_MIN 0x0000
#define WCHAR_MAX 0xffff

#define wchar_t unsigned short

__declspec(dllimport) int swprintf(wchar_t* const _Buffer, size_t const _BufferCount, wchar_t const* const _Format, ...);

0 comments on commit 3c0f8fb

Please sign in to comment.