Compare commits

...

2 Commits

Author SHA1 Message Date
Ed_
96ffca3094 forgot to add Context to c_library.refactor 2024-12-14 00:21:13 -05:00
Ed_
967a044637 Got .lib and .dlls setup for the C11 library 2024-12-14 00:10:07 -05:00
9 changed files with 159 additions and 87 deletions

View File

@ -56,7 +56,8 @@
"new": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"xstddef": "cpp"
"xstddef": "cpp",
"gen_singleheader.h": "c"
},
"C_Cpp.intelliSenseEngineFallback": "disabled",
"mesonbuild.configureOnOpen": true,

View File

@ -7,7 +7,7 @@
#if GEN_COMPILER_MSVC
#ifdef GEN_DYN_LINK
#ifdef GEN_EXPORTS
#ifdef GEN_DYN_EXPORT
#define GEN_API __declspec(dllexport)
#else
#define GEN_API __declspec(dllimport)

View File

@ -350,6 +350,8 @@ word CodeVar, gen_CodeVar
// Code Interface
word Context, gen_Context
namespace code_, gen_code_
word Code_Global, gen_Code_Global

View File

@ -0,0 +1,3 @@
#define GEN_IMPLEMENTATION
#define GEN_DONT_ENFORCE_GEN_TIME_GUARD
#include "gen/gen_singleheader.h"

View File

@ -18,12 +18,12 @@ Push-Location $path_root
$vendor = $null
$release = $null
[bool] $verbose = $false
[bool] $shared = $false
[bool] $dyn_link = $false
[bool] $base = $false
[bool] $segmented = $false
[bool] $singleheader = $false
[bool] $c_library = $false
[bool] $c_lib = $false
[bool] $c_lib_static = $false
[bool] $c_lib_dyn = $false
[bool] $unreal = $false
[bool] $test = $false
@ -37,12 +37,12 @@ if ( $args ) { $args | ForEach-Object {
"verbose" { $verbose = $true }
"release" { $release = $true }
"debug" { $release = $false }
"shared" { $shared = $true }
"dyn_link" { $dyn_link = $true }
"base" { $base = $true }
"segmented" { $segmented = $true }
"singleheader" { $singleheader = $true }
"c_library" { $c_library = $true }
"c_lib" { $c_lib = $true }
"c_lib_static" { $c_lib_static = $true }
"c_lib_dyn" { $c_lib_dyn = $true }
"unreal" { $unreal = $true }
"test" { $test = $true }
}
@ -75,7 +75,9 @@ else {
$cannot_build = $base -eq $false
$cannot_build = $cannot_build -and $segmented -eq $false
$cannot_build = $cannot_build -and $singleheader -eq $false
$cannot_build = $cannot_build -and $c_library -eq $false
$cannot_build = $cannot_build -and $c_lib -eq $false
$cannot_build = $cannot_build -and $c_lib_static -eq $false
$cannot_build = $cannot_build -and $c_lib_dyn -eq $false
$cannot_build = $cannot_build -and $unreal -eq $false
$cannot_build = $cannot_build -and $test -eq $false
if ( $cannot_build ) {
@ -213,7 +215,7 @@ if ( $singleheader )
Pop-Location
}
if ( $c_library )
if ( $c_lib -or $c_lib_static -or $c_lib_dyn )
{
$path_build = join-path $path_c_library build
$path_gen = join-path $path_c_library gen
@ -249,34 +251,38 @@ if ( $c_library )
write-host "`nc_library generator completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
}
if ( $c_lib_static )
{
$includes = @( $path_c_library )
$unit = join-path $path_c_library "gen.c"
$executable = join-path $path_build "gen_c_library_test.exe"
$unit = join-path $path_c_library "gen_c_lib.c"
$path_lib = join-path $path_build "gencpp_c11.lib"
if ($vendor -eq "clang") {
$compiler_args += '-x'
$compiler_args += 'c'
$compiler_args += '-std=c11'
} elseif ($vendor -eq "msvc") {
$compiler_args += "/TC" # Compile as C
$compiler_args += "/Zc:__cplusplus" # Fix __cplusplus macro
$compiler_args += "/std:c11"
$compiler_args = @()
$compiler_args += $flag_all_c
$compiler_args += $flag_updated_cpp_macro
$compiler_args += $flag_c11
$linker_args = @()
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $path_lib
}
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
if ( $c_lib_dyn )
{
$includes = @( $path_c_library )
$unit = join-path $path_c_library "gen_c_lib.c"
$path_dll = join-path $path_build "gencpp_c11.dll"
Push-Location $path_c_library
if ( Test-Path( $executable ) ) {
write-host "`nRunning c_library test"
$time_taken = Measure-Command { & $executable
| ForEach-Object {
write-host `t $_ -ForegroundColor Green
}
}
write-host "`nc_library generator completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
$compiler_args = @()
$compiler_args += $flag_all_c
$compiler_args += $flag_updated_cpp_macro
$compiler_args += $flag_c11
$compiler_args += ( $flag_define + 'GEN_DYN_LINK' )
$compiler_args += ( $flag_define + 'GEN_DYN_EXPORT' )
$linker_args = @()
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $path_dll
}
if ( $unreal )
@ -319,47 +325,24 @@ if ( $unreal )
. $refactor_unreal
}
# TODO(Ed): The unit testing needs a full rewrite
if ( $test -and $false )
if ( $test )
{
$path_gen = join-path $path_test gen
$path_gen_build = join-path $path_gen build
$path_build = join-path $path_test build
$path_original = join-path $path_gen original
$path_components = join-path $path_original components
$path_dependencies = join-path $path_original dependencies
$path_helpers = join-path $path_original helpers
$path_test_c_lib = join-path $path_test c_library
$path_build = join-path $path_test_c_lib build
if ( -not(Test-Path($path_build) )) {
New-Item -ItemType Directory -Path $path_build
}
if ( -not(Test-Path($path_gen) )) {
New-Item -ItemType Directory -Path $path_gen
}
if ( -not(Test-Path($path_gen_build) )) {
New-Item -ItemType Directory -Path $path_gen_build
}
if ( -not(test-path $path_original)) {
new-item -ItemType Directory -Path $path_original
}
if ( -not(test-path $path_components)) {
new-item -ItemType Directory -Path $path_components
}
if ( -not(test-path $path_dependencies)) {
new-item -ItemType Directory -Path $path_dependencies
}
if ( -not(test-path $path_helpers)) {
new-item -ItemType Directory -Path $path_helpers
}
$path_bootstrap = join-path $path_project gen
$includes = @( $path_bootstrap )
$unit = join-path $path_test "test.cpp"
$executable = join-path $path_build "test.exe"
$includes = @( $path_c_library )
$unit = join-path $path_test_c_lib "gen.c"
$executable = join-path $path_build "gen_c_library_test.exe"
$compiler_args = @()
$compiler_args += ( $flag_define + 'GEN_TIME' )
$compiler_args += $flag_all_c
$compiler_args += $flag_updated_cpp_macro
$compiler_args += $flag_c11
$linker_args = @(
$flag_link_win_subsystem_console
@ -367,16 +350,15 @@ if ( $test -and $false )
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
Push-Location $path_test
Write-Host $path_test
Push-Location $path_test_c_lib
if ( Test-Path( $executable ) ) {
write-host "`nRunning test generator"
write-host "`nRunning c_library test"
$time_taken = Measure-Command { & $executable
| ForEach-Object {
write-host `t $_ -ForegroundColor Green
}
}
write-host "`nTest generator completed in $($time_taken.TotalMilliseconds) ms"
write-host "`nc_library generator completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
}

View File

@ -22,6 +22,40 @@ if ( $dev ) {
}
}
# Add new function for running lib.exe
function run-archiver
{
param( $archiver, $library, $lib_args )
write-host "`Creating library $library"
if ( $verbose ) {
write-host "Lib manager config:"
$lib_args | ForEach-Object {
write-host $_ -ForegroundColor Cyan
}
}
$time_taken = Measure-Command {
& $archiver $lib_args 2>&1 | ForEach-Object {
$color = 'White'
switch ($_){
{ $_ -match "error" } { $color = 'Red' ; break }
{ $_ -match "warning" } { $color = 'Yellow'; break }
}
write-host `t $_ -ForegroundColor $color
}
}
if ( $LASTEXITCODE -eq 0 ) {
write-host "$library creation finished in $($time_taken.TotalMilliseconds) ms`n"
return $true
}
else {
write-host "Library creation failed for $library`n" -ForegroundColor Red
return $false
}
}
function run-compiler
{
param( $compiler, $unit, $compiler_args )
@ -95,7 +129,8 @@ function run-linker
if ( $vendor -match "clang" )
{
# https://clang.llvm.org/docs/ClangCommandLineReference.html
$flag_all_c = '-x c'
$flag_all_c = @('-x', 'c')
$flag_c11 = '-std=c11'
$flag_all_cpp = '-x c++'
$flag_compile = '-c'
$flag_color_diagnostics = '-fcolor-diagnostics'
@ -174,8 +209,8 @@ if ( $vendor -match "clang" )
$map = join-path $path_output (split-path $map -Leaf)
# This allows dll reloads at runtime to work (jankily, use below if not interested)
$pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
# $pdb = $binary -replace '\.(exe|dll)$', ".pdb"
# $pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
$pdb = $binary -replace '\.(exe|dll)$', ".pdb"
$compiler_args += @(
$flag_no_color_diagnostics,
@ -253,8 +288,8 @@ if ( $vendor -match "clang" )
$map = join-path $path_output (split-path $map -Leaf)
# This allows dll reloads at runtime to work (jankily, use below if not interested)
$pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
# $pdb = $binary -replace '\.(exe|dll)$', ".pdb"
# $pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
$pdb = $binary -replace '\.(exe|dll)$', ".pdb"
$compiler_args += @(
$flag_no_color_diagnostics,
@ -308,10 +343,22 @@ if ( $vendor -match "clang" )
$linker_args += $_ + '.lib'
}
# Check if output is a static library
# if ( $binary -match '\.lib$' )
# {
# $lib_args = @()
# $lib_args += $flag_nologo
# $lib_args += $flag_link_win_machine_64
# $lib_args += ( $flag_link_win_path_output + $binary )
# $lib_args += $object
# return run-archiver $archiver $binary $lib_args
# }
$linker_args += $object
return run-linker $linker $binary $linker_args
}
$archiver = 'llvm-ar'
$compiler = 'clang++'
$linker = 'lld-link'
}
@ -320,6 +367,7 @@ if ( $vendor -match "msvc" )
{
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
$flag_all_c = '/TC'
$flag_c11 = '/std:c11'
$flag_all_cpp = '/TP'
$flag_compile = '/c'
$flag_debug = '/Zi'
@ -332,6 +380,7 @@ if ( $vendor -match "msvc" )
$flag_dll = '/LD'
$flag_dll_debug = '/LDd'
$flag_linker = '/link'
# $flag_link_lib = '/lib'
$flag_link_dll = '/DLL'
$flag_link_no_incremental = '/INCREMENTAL:NO'
$flag_link_mapfile = '/MAP:'
@ -354,15 +403,17 @@ if ( $vendor -match "msvc" )
$flag_optimized_debug_forceinline = '/d2Obforceinline'
$flag_optimized_debug = '/Zo'
$flag_
$flag_out_name = '/OUT:'
# $flag_out_name = '/OUT:'
$flag_path_interm = '/Fo'
$flag_path_debug = '/Fd'
$flag_path_output = '/Fe'
$flag_preprocess_conform = '/Zc:preprocessor'
$flag_updated_cpp_macro = "/Zc:__cplusplus"
$flag_set_stack_size = '/F'
$flag_syntax_only = '/Zs'
$flag_wall = '/Wall'
$flag_warnings_as_errors = '/WX'
$flag_lib_list = '/LIST'
function build
{
@ -374,8 +425,8 @@ if ( $vendor -match "msvc" )
$map = join-path $path_output (split-path $map -Leaf)
# This allows dll reloads at runtime to work (jankily, use below if not interested)
$pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
# $pdb = $binary -replace '\.(exe|dll)$', ".pdb"
# $pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
$pdb = $binary -replace '\.(exe|dll)$', ".pdb"
$compiler_args += @(
$flag_nologo,
@ -461,8 +512,8 @@ if ( $vendor -match "msvc" )
$map = join-path $path_output (split-path $map -Leaf)
# This allows dll reloads at runtime to work (jankily, use below if not interested)
$pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
# $pdb = $binary -replace '\.(exe|dll)$', ".pdb"
# $pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
$pdb = $binary -replace '\.(exe|dll)$', ".pdb"
$compiler_args += @(
$flag_nologo,
@ -508,6 +559,17 @@ if ( $vendor -match "msvc" )
return $false;
}
# Check if output is a static library
if ( $binary -match '\.lib$' )
{
$lib_args = @()
$lib_args += $flag_nologo
$lib_args += $flag_link_win_machine_64
$lib_args += ( $flag_link_win_path_output + $binary )
$lib_args += $object
return run-archiver $archiver $binary $lib_args
}
$linker_args += @(
$flag_nologo,
$flag_link_win_machine_64,
@ -522,10 +584,19 @@ if ( $vendor -match "msvc" )
else {
}
# Check if output is a dynamic library
if ( $binary -match '\.dll$' ) {
$linker_args += $flag_link_dll
}
$linker_args += $object
# Write-Host "link args:"
# $linker_args | ForEach-Object {
# Write-Host "`t$_" -ForegroundColor Yellow
# }
return run-linker $linker $binary $linker_args
}
$archiver = 'lib'
$compiler = 'cl'
$linker = 'link'
}

View File

@ -4,16 +4,14 @@ Import-Module $misc
$build = Join-Path $PSScriptRoot 'build.ci.ps1'
if ( $IsWindows ) {
& $build release msvc base segmented singleheader unreal c_library msvc debug
}
else {
& $build release clang base segmented singleheader unreal c_library msvc debug
& $build release msvc debug base segmented singleheader unreal c_lib c_lib_static c_lib_dyn
}
$path_root = Get-ScriptRepoRoot
$path_docs = Join-Path $path_root docs
$path_base = Join-Path $path_root base
$path_c_library = Join-Path $path_root gen_c_library
$path_c_library_build = Join-Path $path_c_library build
$path_c_library_gen = Join-Path $path_c_library gen
$path_segmented = Join-Path $path_root gen_segmented
$path_segmented_gen = Join-Path $path_segmented gen
@ -87,6 +85,20 @@ Copy-Item -Verbose -Path $path_c_library_gen\gen.h -Destination $path
Compress-Archive -Path $path_release_content\* -DestinationPath $path_release\gencpp_c11_segmented.zip -Force
Remove-Item -Path $path_release_content -Recurse
# C Library Segmented
prep-ReleaseContent
Copy-Item -Verbose -Path $path_c_library\Readme.md -Destination $path_release_content
Copy-Item -Verbose -Path $path_c_library_gen\gen.dep.c -Destination $path_release_content
Copy-Item -Verbose -Path $path_c_library_gen\gen.dep.h -Destination $path_release_content
Copy-Item -Verbose -Path $path_c_library_gen\gen.c -Destination $path_release_content
Copy-Item -Verbose -Path $path_c_library_gen\gen.h -Destination $path_release_content
Compress-Archive -Path $path_release_content\* -DestinationPath $path_release\gencpp_c11_segmented.zip -Force
Remove-Item -Path $path_release_content -Recurse
# C Lib Static & Dyanmic Libs
Copy-Item -Verbose -Path $path_c_library_build\gencpp_c11.lib -Destination $path_release
Copy-Item -Verbose -Path $path_c_library_build\gencpp_c11.dll -Destination $path_release
# Base
prep-ReleaseContent

View File

@ -1,8 +1,9 @@
#define GEN_IMPLEMENTATION
#include "gen/gen_singleheader.h"
int main()
int gen_main()
{
// init();
__debugbreak();
return 0;
}