mirror of
https://github.com/bshoshany/thread-pool.git
synced 2026-07-21 19:13:00 +04:00
Updated to v5.1.0
This commit is contained in:
+4
-6
@@ -25,7 +25,6 @@ AllowShortLambdasOnASingleLine: Empty
|
|||||||
AllowShortLoopsOnASingleLine: false
|
AllowShortLoopsOnASingleLine: false
|
||||||
AlwaysBreakAfterReturnType: None
|
AlwaysBreakAfterReturnType: None
|
||||||
AlwaysBreakBeforeMultilineStrings: false
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
AlwaysBreakTemplateDeclarations: Yes
|
|
||||||
AttributeMacros: []
|
AttributeMacros: []
|
||||||
BinPackArguments: true
|
BinPackArguments: true
|
||||||
BinPackParameters: true
|
BinPackParameters: true
|
||||||
@@ -45,7 +44,7 @@ BraceWrapping:
|
|||||||
BeforeLambdaBody: true
|
BeforeLambdaBody: true
|
||||||
BeforeWhile: false
|
BeforeWhile: false
|
||||||
IndentBraces: false
|
IndentBraces: false
|
||||||
SplitEmptyFunction: true
|
SplitEmptyFunction: false
|
||||||
SplitEmptyNamespace: true
|
SplitEmptyNamespace: true
|
||||||
SplitEmptyRecord: true
|
SplitEmptyRecord: true
|
||||||
BracedInitializerIndentWidth: 4
|
BracedInitializerIndentWidth: 4
|
||||||
@@ -57,12 +56,11 @@ BreakBeforeConceptDeclarations: true
|
|||||||
BreakBeforeInheritanceComma: false
|
BreakBeforeInheritanceComma: false
|
||||||
BreakBeforeTernaryOperators: true
|
BreakBeforeTernaryOperators: true
|
||||||
BreakConstructorInitializers: BeforeColon
|
BreakConstructorInitializers: BeforeColon
|
||||||
BreakConstructorInitializersBeforeComma: false
|
|
||||||
BreakInheritanceList: BeforeColon
|
BreakInheritanceList: BeforeColon
|
||||||
BreakStringLiterals: true
|
BreakStringLiterals: true
|
||||||
ColumnLimit: 1024
|
BreakTemplateDeclarations: No
|
||||||
|
ColumnLimit: 0
|
||||||
CompactNamespaces: false
|
CompactNamespaces: false
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
|
||||||
ConstructorInitializerIndentWidth: 4
|
ConstructorInitializerIndentWidth: 4
|
||||||
ContinuationIndentWidth: 4
|
ContinuationIndentWidth: 4
|
||||||
Cpp11BracedListStyle: true
|
Cpp11BracedListStyle: true
|
||||||
@@ -99,7 +97,7 @@ ObjCBreakBeforeNestedBlockParam: true
|
|||||||
ObjCSpaceAfterProperty: false
|
ObjCSpaceAfterProperty: false
|
||||||
ObjCSpaceBeforeProtocolList: true
|
ObjCSpaceBeforeProtocolList: true
|
||||||
PPIndentWidth: -1
|
PPIndentWidth: -1
|
||||||
PackConstructorInitializers: BinPack
|
PackConstructorInitializers: CurrentLine
|
||||||
PenaltyBreakAssignment: 0
|
PenaltyBreakAssignment: 0
|
||||||
PenaltyBreakBeforeFirstCallParameter: 0
|
PenaltyBreakBeforeFirstCallParameter: 0
|
||||||
PenaltyBreakComment: 0
|
PenaltyBreakComment: 0
|
||||||
|
|||||||
+10
-2
@@ -1,7 +1,8 @@
|
|||||||
CheckOptions:
|
CheckOptions:
|
||||||
|
cppcoreguidelines-pro-type-member-init.IgnoreArrays: true
|
||||||
|
cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: true
|
||||||
misc-const-correctness.WarnPointersAsValues: true
|
misc-const-correctness.WarnPointersAsValues: true
|
||||||
misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true
|
misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true
|
||||||
readability-magic-numbers.IgnoredIntegerValues: 0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10
|
|
||||||
Checks: >
|
Checks: >
|
||||||
*,
|
*,
|
||||||
-abseil-*,
|
-abseil-*,
|
||||||
@@ -11,6 +12,10 @@ Checks: >
|
|||||||
-bugprone-easily-swappable-parameters,
|
-bugprone-easily-swappable-parameters,
|
||||||
-bugprone-empty-catch,
|
-bugprone-empty-catch,
|
||||||
-cert-err58-cpp,
|
-cert-err58-cpp,
|
||||||
|
-clang-analyzer-alpha.*,
|
||||||
|
-clang-analyzer-debug.*,
|
||||||
|
-clang-analyzer-fuchsia.*,
|
||||||
|
-clang-analyzer-webkit.*,
|
||||||
-cppcoreguidelines-avoid-c-arrays,
|
-cppcoreguidelines-avoid-c-arrays,
|
||||||
-cppcoreguidelines-avoid-do-while,
|
-cppcoreguidelines-avoid-do-while,
|
||||||
-cppcoreguidelines-avoid-magic-numbers,
|
-cppcoreguidelines-avoid-magic-numbers,
|
||||||
@@ -26,15 +31,16 @@ Checks: >
|
|||||||
-google-*,
|
-google-*,
|
||||||
-hicpp-avoid-c-arrays,
|
-hicpp-avoid-c-arrays,
|
||||||
-hicpp-braces-around-statements,
|
-hicpp-braces-around-statements,
|
||||||
|
-hicpp-member-init,
|
||||||
-hicpp-no-array-decay,
|
-hicpp-no-array-decay,
|
||||||
-hicpp-signed-bitwise,
|
-hicpp-signed-bitwise,
|
||||||
|
-hicpp-special-member-functions,
|
||||||
-hicpp-use-auto,
|
-hicpp-use-auto,
|
||||||
-hicpp-vararg,
|
-hicpp-vararg,
|
||||||
-linuxkernel-*,
|
-linuxkernel-*,
|
||||||
-llvm-*,
|
-llvm-*,
|
||||||
-llvmlibc-*,
|
-llvmlibc-*,
|
||||||
-misc-definitions-in-headers,
|
-misc-definitions-in-headers,
|
||||||
-misc-use-internal-linkage,
|
|
||||||
-modernize-avoid-bind,
|
-modernize-avoid-bind,
|
||||||
-modernize-avoid-c-arrays,
|
-modernize-avoid-c-arrays,
|
||||||
-modernize-use-auto,
|
-modernize-use-auto,
|
||||||
@@ -51,6 +57,8 @@ Checks: >
|
|||||||
-readability-braces-around-statements,
|
-readability-braces-around-statements,
|
||||||
-readability-function-cognitive-complexity,
|
-readability-function-cognitive-complexity,
|
||||||
-readability-identifier-length,
|
-readability-identifier-length,
|
||||||
|
-readability-magic-numbers,
|
||||||
|
-readability-use-concise-preprocessor-directives,
|
||||||
-zircon-*,
|
-zircon-*,
|
||||||
HeaderFileExtensions: [h, hpp, cppm]
|
HeaderFileExtensions: [h, hpp, cppm]
|
||||||
HeaderFilterRegex: .*
|
HeaderFilterRegex: .*
|
||||||
|
|||||||
@@ -32,4 +32,4 @@ What behavior did you expect to get? What actually happened? If the code failed
|
|||||||
|
|
||||||
**Additional information**
|
**Additional information**
|
||||||
|
|
||||||
Include any additional information here.
|
Include any additional information here.
|
||||||
|
|||||||
@@ -21,4 +21,4 @@ Please attach the log file generated by the automated test program to this issue
|
|||||||
|
|
||||||
**Additional information**
|
**Additional information**
|
||||||
|
|
||||||
Include any additional information here.
|
Include any additional information here.
|
||||||
|
|||||||
@@ -18,4 +18,4 @@ An example of code that utilizes the suggested feature. Paste or write it betwee
|
|||||||
|
|
||||||
**Additional information**
|
**Additional information**
|
||||||
|
|
||||||
Include any additional information here.
|
Include any additional information here.
|
||||||
|
|||||||
@@ -27,4 +27,4 @@ If so, please provide information about the test system(s):
|
|||||||
|
|
||||||
**Additional information**
|
**Additional information**
|
||||||
|
|
||||||
Include any additional information here.
|
Include any additional information here.
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
build
|
build
|
||||||
temp
|
temp
|
||||||
|
default_args.txt
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "linux-clang-x64",
|
"intelliSenseMode": "linux-clang-x64",
|
||||||
"name": "Clang C++17"
|
"name": "Clang C++17"
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "linux-clang-x64",
|
"intelliSenseMode": "linux-clang-x64",
|
||||||
"name": "Clang C++20"
|
"name": "Clang C++20"
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "linux-clang-x64",
|
"intelliSenseMode": "linux-clang-x64",
|
||||||
"name": "Clang C++23"
|
"name": "Clang C++23"
|
||||||
@@ -68,7 +68,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
"intelliSenseMode": "linux-gcc-x64",
|
||||||
"name": "GCC C++17"
|
"name": "GCC C++17"
|
||||||
@@ -84,7 +84,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
"intelliSenseMode": "linux-gcc-x64",
|
||||||
"name": "GCC C++20"
|
"name": "GCC C++20"
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
"intelliSenseMode": "linux-gcc-x64",
|
||||||
"name": "GCC C++23"
|
"name": "GCC C++23"
|
||||||
|
|||||||
+59
-59
@@ -1,59 +1,59 @@
|
|||||||
{
|
{
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (Clang C++17)",
|
"name": "Build and debug (Clang C++17)",
|
||||||
"preLaunchTask": "Build for debugging (Clang C++17)",
|
"preLaunchTask": "Build for debugging (Clang C++17)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp17",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp17",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "lldb"
|
"type": "lldb"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (Clang C++20)",
|
"name": "Build and debug (Clang C++20)",
|
||||||
"preLaunchTask": "Build for debugging (Clang C++20)",
|
"preLaunchTask": "Build for debugging (Clang C++20)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp20",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp20",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "lldb"
|
"type": "lldb"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (Clang C++23)",
|
"name": "Build and debug (Clang C++23)",
|
||||||
"preLaunchTask": "Build for debugging (Clang C++23)",
|
"preLaunchTask": "Build for debugging (Clang C++23)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp23",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp23",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "lldb"
|
"type": "lldb"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (GCC C++17)",
|
"name": "Build and debug (GCC C++17)",
|
||||||
"preLaunchTask": "Build for debugging (GCC C++17)",
|
"preLaunchTask": "Build for debugging (GCC C++17)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-gcc-cpp17",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-gcc-cpp17",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "cppdbg"
|
"type": "cppdbg"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (GCC C++20)",
|
"name": "Build and debug (GCC C++20)",
|
||||||
"preLaunchTask": "Build for debugging (GCC C++20)",
|
"preLaunchTask": "Build for debugging (GCC C++20)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-gcc-cpp20",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-gcc-cpp20",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "cppdbg"
|
"type": "cppdbg"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (GCC C++23)",
|
"name": "Build and debug (GCC C++23)",
|
||||||
"preLaunchTask": "Build for debugging (GCC C++23)",
|
"preLaunchTask": "Build for debugging (GCC C++23)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-gcc-cpp23",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-gcc-cpp23",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "cppdbg"
|
"type": "cppdbg"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": "0.2.0"
|
"version": "0.2.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"C_Cpp.codeAnalysis.exclude": {
|
||||||
|
"misc/**": true,
|
||||||
|
"temp/**": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -470,8 +470,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [
|
"args": [
|
||||||
"scripts/clear_folder.py",
|
"scripts/compile_cpp.py",
|
||||||
"../build"
|
"-b",
|
||||||
|
"-v"
|
||||||
],
|
],
|
||||||
"command": "python3",
|
"command": "python3",
|
||||||
"detail": "Delete all files in the build folder.",
|
"detail": "Delete all files in the build folder.",
|
||||||
@@ -490,13 +491,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [
|
"args": [
|
||||||
"scripts/clear_folder.py",
|
"scripts/compile_cpp.py",
|
||||||
"../temp"
|
"${file}",
|
||||||
|
"-t=release",
|
||||||
|
"-y",
|
||||||
|
"-v"
|
||||||
],
|
],
|
||||||
"command": "python3",
|
"command": "python3",
|
||||||
"detail": "Delete all files in the temp folder.",
|
"detail": "Compile active file using all available compilers and all relevant C++ standards with warning and optimization flags.",
|
||||||
"group": "test",
|
"group": "test",
|
||||||
"label": "Clear temp folder",
|
"label": "Build all optimized (all compilers and standards)",
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"clear": false,
|
"clear": false,
|
||||||
"echo": true,
|
"echo": true,
|
||||||
@@ -510,12 +514,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [
|
"args": [
|
||||||
"scripts/test_all.py"
|
"scripts/compile_cpp.py",
|
||||||
|
"${file}",
|
||||||
|
"-t=release",
|
||||||
|
"-y",
|
||||||
|
"-r",
|
||||||
|
"-v"
|
||||||
],
|
],
|
||||||
"command": "python3",
|
"command": "python3",
|
||||||
"detail": "Compile and run the test program with all available compilers and all relevant C++ standards.",
|
"detail": "Compile active file using all available compilers and all relevant C++ standards with warning and optimization flags and run the program.",
|
||||||
"group": "test",
|
"group": "test",
|
||||||
"label": "Run all tests",
|
"label": "Build all optimized and run (all compilers and standards)",
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"clear": false,
|
"clear": false,
|
||||||
"echo": true,
|
"echo": true,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "macos-clang-x64",
|
"intelliSenseMode": "macos-clang-x64",
|
||||||
"name": "Clang C++17"
|
"name": "Clang C++17"
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "macos-clang-x64",
|
"intelliSenseMode": "macos-clang-x64",
|
||||||
"name": "Clang C++20"
|
"name": "Clang C++20"
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "macos-clang-x64",
|
"intelliSenseMode": "macos-clang-x64",
|
||||||
"name": "Clang C++23"
|
"name": "Clang C++23"
|
||||||
|
|||||||
+32
-32
@@ -1,32 +1,32 @@
|
|||||||
{
|
{
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (Clang C++17)",
|
"name": "Build and debug (Clang C++17)",
|
||||||
"preLaunchTask": "Build for debugging (Clang C++17)",
|
"preLaunchTask": "Build for debugging (Clang C++17)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp17",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp17",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "lldb"
|
"type": "lldb"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (Clang C++20)",
|
"name": "Build and debug (Clang C++20)",
|
||||||
"preLaunchTask": "Build for debugging (Clang C++20)",
|
"preLaunchTask": "Build for debugging (Clang C++20)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp20",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp20",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "lldb"
|
"type": "lldb"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (Clang C++23)",
|
"name": "Build and debug (Clang C++23)",
|
||||||
"preLaunchTask": "Build for debugging (Clang C++23)",
|
"preLaunchTask": "Build for debugging (Clang C++23)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp23",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp23",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "lldb"
|
"type": "lldb"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": "0.2.0"
|
"version": "0.2.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"C_Cpp.codeAnalysis.exclude": {
|
||||||
|
"misc/**": true,
|
||||||
|
"temp/**": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -236,8 +236,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [
|
"args": [
|
||||||
"scripts/clear_folder.py",
|
"scripts/compile_cpp.py",
|
||||||
"../build"
|
"-b",
|
||||||
|
"-v"
|
||||||
],
|
],
|
||||||
"command": "python3",
|
"command": "python3",
|
||||||
"detail": "Delete all files in the build folder.",
|
"detail": "Delete all files in the build folder.",
|
||||||
@@ -256,13 +257,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [
|
"args": [
|
||||||
"scripts/clear_folder.py",
|
"scripts/compile_cpp.py",
|
||||||
"../temp"
|
"${file}",
|
||||||
|
"-t=release",
|
||||||
|
"-y",
|
||||||
|
"-v"
|
||||||
],
|
],
|
||||||
"command": "python3",
|
"command": "python3",
|
||||||
"detail": "Delete all files in the temp folder.",
|
"detail": "Compile active file using all available compilers and all relevant C++ standards with warning and optimization flags.",
|
||||||
"group": "test",
|
"group": "test",
|
||||||
"label": "Clear temp folder",
|
"label": "Build all optimized (all compilers and standards)",
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"clear": false,
|
"clear": false,
|
||||||
"echo": true,
|
"echo": true,
|
||||||
@@ -276,12 +280,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [
|
"args": [
|
||||||
"scripts/test_all.py"
|
"scripts/compile_cpp.py",
|
||||||
|
"${file}",
|
||||||
|
"-t=release",
|
||||||
|
"-y",
|
||||||
|
"-r",
|
||||||
|
"-v"
|
||||||
],
|
],
|
||||||
"command": "python3",
|
"command": "python3",
|
||||||
"detail": "Compile and run the test program with all available compilers and all relevant C++ standards.",
|
"detail": "Compile active file using all available compilers and all relevant C++ standards with warning and optimization flags and run the program.",
|
||||||
"group": "test",
|
"group": "test",
|
||||||
"label": "Run all tests",
|
"label": "Build all optimized and run (all compilers and standards)",
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"clear": false,
|
"clear": false,
|
||||||
"echo": true,
|
"echo": true,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "windows-clang-x64",
|
"intelliSenseMode": "windows-clang-x64",
|
||||||
"name": "Clang C++17"
|
"name": "Clang C++17"
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "windows-clang-x64",
|
"intelliSenseMode": "windows-clang-x64",
|
||||||
"name": "Clang C++20"
|
"name": "Clang C++20"
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "windows-clang-x64",
|
"intelliSenseMode": "windows-clang-x64",
|
||||||
"name": "Clang C++23"
|
"name": "Clang C++23"
|
||||||
@@ -68,7 +68,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "windows-gcc-x64",
|
"intelliSenseMode": "windows-gcc-x64",
|
||||||
"name": "GCC C++17"
|
"name": "GCC C++17"
|
||||||
@@ -84,7 +84,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "windows-gcc-x64",
|
"intelliSenseMode": "windows-gcc-x64",
|
||||||
"name": "GCC C++20"
|
"name": "GCC C++20"
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "windows-gcc-x64",
|
"intelliSenseMode": "windows-gcc-x64",
|
||||||
"name": "GCC C++23"
|
"name": "GCC C++23"
|
||||||
@@ -116,7 +116,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "windows-msvc-x64",
|
"intelliSenseMode": "windows-msvc-x64",
|
||||||
"name": "MSVC C++17"
|
"name": "MSVC C++17"
|
||||||
@@ -132,7 +132,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "windows-msvc-x64",
|
"intelliSenseMode": "windows-msvc-x64",
|
||||||
"name": "MSVC C++20"
|
"name": "MSVC C++20"
|
||||||
@@ -148,7 +148,7 @@
|
|||||||
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
"BS_THREAD_POOL_NATIVE_EXTENSIONS"
|
||||||
],
|
],
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/include"
|
||||||
],
|
],
|
||||||
"intelliSenseMode": "windows-msvc-x64",
|
"intelliSenseMode": "windows-msvc-x64",
|
||||||
"name": "MSVC C++23"
|
"name": "MSVC C++23"
|
||||||
|
|||||||
+89
-89
@@ -1,89 +1,89 @@
|
|||||||
{
|
{
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (Clang C++17)",
|
"name": "Build and debug (Clang C++17)",
|
||||||
"preLaunchTask": "Build for debugging (Clang C++17)",
|
"preLaunchTask": "Build for debugging (Clang C++17)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp17",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp17",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "lldb"
|
"type": "lldb"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (Clang C++20)",
|
"name": "Build and debug (Clang C++20)",
|
||||||
"preLaunchTask": "Build for debugging (Clang C++20)",
|
"preLaunchTask": "Build for debugging (Clang C++20)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp20",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp20",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "lldb"
|
"type": "lldb"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (Clang C++23)",
|
"name": "Build and debug (Clang C++23)",
|
||||||
"preLaunchTask": "Build for debugging (Clang C++23)",
|
"preLaunchTask": "Build for debugging (Clang C++23)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp23",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-clang-cpp23",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "lldb"
|
"type": "lldb"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (GCC C++17)",
|
"name": "Build and debug (GCC C++17)",
|
||||||
"preLaunchTask": "Build for debugging (GCC C++17)",
|
"preLaunchTask": "Build for debugging (GCC C++17)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-gcc-cpp17",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-gcc-cpp17",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "cppdbg"
|
"type": "cppdbg"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (GCC C++20)",
|
"name": "Build and debug (GCC C++20)",
|
||||||
"preLaunchTask": "Build for debugging (GCC C++20)",
|
"preLaunchTask": "Build for debugging (GCC C++20)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-gcc-cpp20",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-gcc-cpp20",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "cppdbg"
|
"type": "cppdbg"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (GCC C++23)",
|
"name": "Build and debug (GCC C++23)",
|
||||||
"preLaunchTask": "Build for debugging (GCC C++23)",
|
"preLaunchTask": "Build for debugging (GCC C++23)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-gcc-cpp23",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-gcc-cpp23",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "cppdbg"
|
"type": "cppdbg"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (MSVC C++17)",
|
"name": "Build and debug (MSVC C++17)",
|
||||||
"preLaunchTask": "Build for debugging (MSVC C++17)",
|
"preLaunchTask": "Build for debugging (MSVC C++17)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-msvc-cpp17",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-msvc-cpp17",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "cppvsdbg"
|
"type": "cppvsdbg"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (MSVC C++20)",
|
"name": "Build and debug (MSVC C++20)",
|
||||||
"preLaunchTask": "Build for debugging (MSVC C++20)",
|
"preLaunchTask": "Build for debugging (MSVC C++20)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-msvc-cpp20",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-msvc-cpp20",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "cppvsdbg"
|
"type": "cppvsdbg"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"cwd": "${workspaceFolder}${/}build",
|
"cwd": "${workspaceFolder}${/}build",
|
||||||
"name": "Build and debug (MSVC C++23)",
|
"name": "Build and debug (MSVC C++23)",
|
||||||
"preLaunchTask": "Build for debugging (MSVC C++23)",
|
"preLaunchTask": "Build for debugging (MSVC C++23)",
|
||||||
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-msvc-cpp23",
|
"program": "${workspaceFolder}${/}build${/}${fileBasenameNoExtension}_debug-msvc-cpp23",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "cppvsdbg"
|
"type": "cppvsdbg"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": "0.2.0"
|
"version": "0.2.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"C_Cpp.codeAnalysis.clangTidy.args": [
|
||||||
|
"--extra-arg-before=--target=x86_64-pc-windows-msvc",
|
||||||
|
],
|
||||||
|
"C_Cpp.codeAnalysis.exclude": {
|
||||||
|
"misc/**": true,
|
||||||
|
"temp/**": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -704,8 +704,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [
|
"args": [
|
||||||
"scripts/clear_folder.py",
|
"scripts/compile_cpp.py",
|
||||||
"../build"
|
"-b",
|
||||||
|
"-v"
|
||||||
],
|
],
|
||||||
"command": "python",
|
"command": "python",
|
||||||
"detail": "Delete all files in the build folder.",
|
"detail": "Delete all files in the build folder.",
|
||||||
@@ -724,13 +725,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [
|
"args": [
|
||||||
"scripts/clear_folder.py",
|
"scripts/compile_cpp.py",
|
||||||
"../temp"
|
"${file}",
|
||||||
|
"-t=release",
|
||||||
|
"-y",
|
||||||
|
"-v"
|
||||||
],
|
],
|
||||||
"command": "python",
|
"command": "python",
|
||||||
"detail": "Delete all files in the temp folder.",
|
"detail": "Compile active file using all available compilers and all relevant C++ standards with warning and optimization flags.",
|
||||||
"group": "test",
|
"group": "test",
|
||||||
"label": "Clear temp folder",
|
"label": "Build all optimized (all compilers and standards)",
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"clear": false,
|
"clear": false,
|
||||||
"echo": true,
|
"echo": true,
|
||||||
@@ -744,12 +748,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [
|
"args": [
|
||||||
"scripts/test_all.py"
|
"scripts/compile_cpp.py",
|
||||||
|
"${file}",
|
||||||
|
"-t=release",
|
||||||
|
"-y",
|
||||||
|
"-r",
|
||||||
|
"-v"
|
||||||
],
|
],
|
||||||
"command": "python",
|
"command": "python",
|
||||||
"detail": "Compile and run the test program with all available compilers and all relevant C++ standards.",
|
"detail": "Compile active file using all available compilers and all relevant C++ standards with warning and optimization flags and run the program.",
|
||||||
"group": "test",
|
"group": "test",
|
||||||
"label": "Run all tests",
|
"label": "Build all optimized and run (all compilers and standards)",
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"clear": false,
|
"clear": false,
|
||||||
"echo": true,
|
"echo": true,
|
||||||
|
|||||||
+46
-1
@@ -6,6 +6,7 @@ Website: <https://baraksh.com/>\
|
|||||||
GitHub: <https://github.com/bshoshany>
|
GitHub: <https://github.com/bshoshany>
|
||||||
|
|
||||||
* [Version history](#version-history)
|
* [Version history](#version-history)
|
||||||
|
* [v5.1.0 (2026-01-03)](#v510-2026-01-03)
|
||||||
* [v5.0.0 (2024-12-19)](#v500-2024-12-19)
|
* [v5.0.0 (2024-12-19)](#v500-2024-12-19)
|
||||||
* [v4.1.0 (2024-03-22)](#v410-2024-03-22)
|
* [v4.1.0 (2024-03-22)](#v410-2024-03-22)
|
||||||
* [v4.0.1 (2023-12-28)](#v401-2023-12-28)
|
* [v4.0.1 (2023-12-28)](#v401-2023-12-28)
|
||||||
@@ -30,6 +31,50 @@ GitHub: <https://github.com/bshoshany>
|
|||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
### v5.1.0 (2026-01-03)
|
||||||
|
|
||||||
|
* New/changed features:
|
||||||
|
* Added `detach_bulk()` and `submit_bulk()` member functions to submit tasks in bulk. You can pass either a range of iterators or a container. The mutex protecting the task queue is locked only once for the entire bulk submission, which should improve performance when submitting a large number of tasks; if the tasks were submitted using individual calls to `detach_task()` or `submit_task()` instead, the mutex would need to be locked and unlocked for each task.
|
||||||
|
* `detach_blocks()`/`detach_loop()`/`detach_sequence()` and `submit_blocks()`/`submit_loop()`/`submit_sequence()` now use `detach_bulk()` and `submit_bulk()`, respectively, under the hood for increased performance (the API remains the same). They have also been refactored using helper functions and custom function object classes to reduce code duplication.
|
||||||
|
* All `submit_*` member functions now use a C++17/20 polyfill for `std::move_only_function` when C++23 is not available (or when using libc++, which at the time of this release has not implemented it yet). This allows them to work without using `std::shared_ptr`, which should increase performance.
|
||||||
|
* If the native extensions are enabled, a pool created with the default constructor will now only use the number of threads available to the process, as obtained from `BS::get_os_process_affinity()`, which can be less than the number of hardware threads. See [#161](https://github.com/bshoshany/thread-pool/issues/161).
|
||||||
|
* Since importing the C++ Standard Library using `import std` is now supported by all 3 major compilers, the library (and test program) will now use `import std` whenever the macro `BS_THREAD_POOL_IMPORT_STD` is defined, as long as C++23 is enabled, without performing any additional checks for compiler or standard library support (aside from the workaround for GCC mentioned below).
|
||||||
|
* The `BS::tp` enumeration is now properly defined as an `enum class` with the appropriate bitwise operators.
|
||||||
|
* Removed the polyfills for `std::counting_semaphore` and `std::binary_semaphore` from `BS_thread_pool.hpp`, as they are not used by the library itself, to reduce the size of the header file. If you need them, you can copy them from the test program `BS_thread_pool_test.cpp`.
|
||||||
|
* On Windows, if the native extensions are enabled, `WIN32_LEAN_AND_MEAN` is now defined before including `<windows.h>` to reduce compilation time.
|
||||||
|
* Bug fixes:
|
||||||
|
* The system macros `major` and `minor` (from `<sys/sysmacros.h>` on Linux) or `min` and `max` (from `<windows.h>` on Windows) are now automatically undefined if they are detected, to prevent compilation errors. This was also done previously, but only under certain conditions; now it is done unconditionally, as some users reported issues. On Windows, `NOMINMAX` is now defined before including `<windows.h>`, but the `min` and `max` macros are still undefined independently.
|
||||||
|
* `BS::wait_deadlock` is now only exported by the module if exceptions are enabled, preventing a compiler error. See [#160](https://github.com/bshoshany/thread-pool/pull/160).
|
||||||
|
* Fixed a typo in `BS::thread_pool::submit_sequence()` which caused the wrong number of futures to be reserved, potentially resulting in unnecessary reallocations.
|
||||||
|
* `BS::multi_future<T>::wait_until` now correctly waits using the specific clock type passed in the template parameter.
|
||||||
|
* Fixed a bug where `reset()` failed to notify worker threads if the pool was unpaused before resetting.
|
||||||
|
* `get_os_thread_affinity()` and `set_os_thread_affinity()` now return `std::nullopt` and `false` (respectively) on Android, as the API is not supported. See [#163](https://github.com/bshoshany/thread-pool/pull/163).
|
||||||
|
* Tests:
|
||||||
|
* The test program `BS_thread_pool_test.cpp` now prints colored output for better readability. This can be disabled by setting the `NO_COLOR` environment variable.
|
||||||
|
* The test program now prints out the Mandelbrot set it generates, downsampled to fit in a terminal window (at 120 character width). This will be in 24-bit color in the terminal, and in monochrome using Unicode blocks in the log file. (If `NO_COLOR` is set, the terminal output will also be in monochrome.)
|
||||||
|
* The test program now looks for `default_args.txt` in both the current folder and the parent folder when reading default command line arguments.
|
||||||
|
* Documentation:
|
||||||
|
* Added an example in `README.md` for getting and setting process affinity.
|
||||||
|
* Removed the suggestion in `README.md` to use the `-pthread` flag on Linux/macOS, as it does not seem to be necessary in order to use the library, at least on the systems I tested with. If you are using a system that requires it, then you probably already know about it.
|
||||||
|
* Updated the instructions in `README.md` for compiling with GCC using `import BS.thread_pool`, and added instructions on how to compile the `std` module with GNU libstdc++.
|
||||||
|
* Fixed many typos and inconsistencies in `README.md`.
|
||||||
|
* Known issues:
|
||||||
|
* At the time of this release, there is a bug in Clang with libc++ where using `std::jthread` in a C++20 module causes a compilation error. As a workaround, until the bug is fixed, the thread pool library automatically falls back to `std::thread` if it detects that Clang and libc++ are being used together with C++20 modules. This workaround can be disabled by defining `BS_THREAD_POOL_DISABLE_WORKAROUNDS` when compiling the module.
|
||||||
|
* At the time of this release, there is a bug when using GCC with libstdc++ on Windows via MSYS2 where the `BS.thread_pool` module doesn't compile if both native extensions and `import std` are enabled. As a workaround, until the bug is fixed, the thread pool library automatically falls back to header files if it detects that GCC and libstdc++ are being used together with the C++23 `std` module on Windows. This workaround can be disabled by defining `BS_THREAD_POOL_DISABLE_WORKAROUNDS` when compiling the module.
|
||||||
|
* Development:
|
||||||
|
* The Python script I use for compiling the test program, `compile_cpp.py`, has received numerous improvements:
|
||||||
|
* The script now supports `import std` with GCC in addition to Clang and MSVC.
|
||||||
|
* The script now only recompiles the program if the source file(s), module(s), and optional additional dependencies (added using the flag `-n`/`--deps` or the `deps` field in `compile_cpp.yaml`) have changed since the binary was created. Use `-e`/`--force` to force recompilation.
|
||||||
|
* The script now allows disabling exceptions by either defining `disable_exceptions: true` in `compile_cpp.yaml` or using the flag `-x=true`/`--disable-exceptions=true` (the flag overrides the YAML file).
|
||||||
|
* The script can now compile modules independently using the `-l`/`--as-module` flag.
|
||||||
|
* The script can now clear the output folder using the `-b`/`--clear-output` flag (replaces the `clear_folder.py` script from the previous release).
|
||||||
|
* The script can now test compilation using all possible combinations of compilers and C++ standards available in the system using the `-y`/`--try-all` flag (replaces the `test_all.py` script from the previous release).
|
||||||
|
* The script now automatically detects the Visual Studio installation path on Windows.
|
||||||
|
* The script now implements a more robust mechanism for finding the `std` module.
|
||||||
|
* The script now prints colored output for better readability. This can be disabled by setting the `NO_COLOR` environment variable.
|
||||||
|
* The script no longer disables optimizations when compiling with GCC and modules (since that bug is fixed in recent versions of GCC).
|
||||||
|
* Added a VS Code task to compile the test program (or the active file) with all available compilers and all relevant C++ standards, but without running it, to quickly check for compiler compatibility issues.
|
||||||
|
|
||||||
### v5.0.0 (2024-12-19)
|
### v5.0.0 (2024-12-19)
|
||||||
|
|
||||||
* A major new release with many new features, improvements, bug fixes, and performance optimizations! Please note that code written using previous releases may need to be modified to work with the new release. The changes needed to migrate to the new API are explicitly indicated below for your convenience.
|
* A major new release with many new features, improvements, bug fixes, and performance optimizations! Please note that code written using previous releases may need to be modified to work with the new release. The changes needed to migrate to the new API are explicitly indicated below for your convenience.
|
||||||
@@ -172,7 +217,7 @@ GitHub: <https://github.com/bshoshany>
|
|||||||
* **Development:**
|
* **Development:**
|
||||||
* A Python script `compile_cpp.py` has been added to the repository, in the `scripts` folder. It can be used to compile any C++ source file with different compilers on different platforms. The compilation parameters can be configured using command line arguments and/or via an optional YAML configuration file `compile_cpp.yaml` which specifies defined macros, extra compiler flags (per compiler), include folders, modules, and the output folder.
|
* A Python script `compile_cpp.py` has been added to the repository, in the `scripts` folder. It can be used to compile any C++ source file with different compilers on different platforms. The compilation parameters can be configured using command line arguments and/or via an optional YAML configuration file `compile_cpp.yaml` which specifies defined macros, extra compiler flags (per compiler), include folders, modules, and the output folder.
|
||||||
* I wrote this script to make it easier for me to test the library with different combinations of compilers, standards, and platforms using the built-in Visual Studio Code tasks. I also included three `.vscode` folders (one for each OS) in the repository, with appropriate `c_cpp_properties.json`, `launch.json`, and `tasks.json` files that utilize this script, in case you want to use it in your own projects. However, note that this script is not meant to replace CMake or any full-fledged build system, it's just a convenient script for developing single-header libraries like this one or other small projects.
|
* I wrote this script to make it easier for me to test the library with different combinations of compilers, standards, and platforms using the built-in Visual Studio Code tasks. I also included three `.vscode` folders (one for each OS) in the repository, with appropriate `c_cpp_properties.json`, `launch.json`, and `tasks.json` files that utilize this script, in case you want to use it in your own projects. However, note that this script is not meant to replace CMake or any full-fledged build system, it's just a convenient script for developing single-header libraries like this one or other small projects.
|
||||||
* The `compile_cpp.py` script also transparently handles C++20 modules and importing the C++ Standard Library as a module in C++23. Therefore, users of this library who wish to import it as a C+20 module may find this script particularly useful.
|
* The `compile_cpp.py` script also transparently handles C++20 modules and importing the C++ Standard Library as a module in C++23. Therefore, users of this library who wish to import it as a C++20 module may find this script particularly useful.
|
||||||
* Another Python script `test_all.py` in the `scripts` folder replaces the old PowerShell test script. Tests are now performed in C++17, C++20, and C++23 modes, using all compilers available in the system (Clang, GCC, and/or MSVC). Since there are so many tests, the test script now no longer performs the benchmarks, as that would take too long.
|
* Another Python script `test_all.py` in the `scripts` folder replaces the old PowerShell test script. Tests are now performed in C++17, C++20, and C++23 modes, using all compilers available in the system (Clang, GCC, and/or MSVC). Since there are so many tests, the test script now no longer performs the benchmarks, as that would take too long.
|
||||||
* A final Python script `clear_folder.py` in the `scripts` folder is used to clean up output and temporary folders, and integrates with VS Code tasks.
|
* A final Python script `clear_folder.py` in the `scripts` folder is used to clean up output and temporary folders, and integrates with VS Code tasks.
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -9,4 +9,4 @@
|
|||||||
url = {https://www.sciencedirect.com/science/article/pii/S235271102400058X},
|
url = {https://www.sciencedirect.com/science/article/pii/S235271102400058X},
|
||||||
volume = {26},
|
volume = {26},
|
||||||
year = {2024}
|
year = {2024}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -22,4 +22,4 @@ preferred-citation:
|
|||||||
repository-code: https://github.com/bshoshany/thread-pool
|
repository-code: https://github.com/bshoshany/thread-pool
|
||||||
title: A C++17 Thread Pool for High-Performance Scientific Computing
|
title: A C++17 Thread Pool for High-Performance Scientific Computing
|
||||||
type: software
|
type: software
|
||||||
url: https://github.com/bshoshany/thread-pool
|
url: https://github.com/bshoshany/thread-pool
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 Barak Shoshany
|
Copyright (c) 2021-2026 Barak Shoshany
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
+11
-5
@@ -1,25 +1,31 @@
|
|||||||
# A list of macros to define when compiling the source files.
|
# A list of macros to define when compiling the source files.
|
||||||
defines: [BS_THREAD_POOL_TEST_IMPORT_MODULE, BS_THREAD_POOL_IMPORT_STD, BS_THREAD_POOL_NATIVE_EXTENSIONS]
|
defines: [BS_THREAD_POOL_TEST_IMPORT_MODULE, BS_THREAD_POOL_IMPORT_STD, BS_THREAD_POOL_NATIVE_EXTENSIONS]
|
||||||
|
# A list of dependencies, such as header files or libraries. All source files compiled using this script will be recompiled if any of these files change. (Note that this is not used for C++20 modules, which have their own dependencies, listed in the modules map.)
|
||||||
|
deps: [include/BS_thread_pool.hpp]
|
||||||
|
# Whether to disable exceptions.
|
||||||
|
disable_exceptions: false
|
||||||
# A map of flags to pass to each compiler. The compiler should be one of [cl, clang++, g++]. The flags should be a list of strings.
|
# A map of flags to pass to each compiler. The compiler should be one of [cl, clang++, g++]. The flags should be a list of strings.
|
||||||
flags:
|
flags:
|
||||||
cl: [/W4]
|
cl: [/W4, /D_CRT_SECURE_NO_WARNINGS]
|
||||||
clang++: [-Wall, -Wextra, -Wconversion, -Wsign-conversion, -Wpedantic, -Wshadow, -Weffc++, -march=native, -fcolor-diagnostics, -fansi-escape-codes, -stdlib=libc++]
|
clang++: [-Wall, -Wextra, -Wconversion, -Wsign-conversion, -Wpedantic, -Wshadow, -Weffc++, -Wdocumentation, -march=native, -fcolor-diagnostics, -fansi-escape-codes, -stdlib=libc++]
|
||||||
g++: [-Wall, -Wextra, -Wconversion, -Wpedantic, -Wshadow, -Wuseless-cast, -march=native, -fdiagnostics-color=always]
|
g++: [-Wall, -Wextra, -Wconversion, -Wsign-conversion, -Wpedantic, -Wshadow, -Wuseless-cast, -march=native, -fdiagnostics-color=always, -Wnrvo]
|
||||||
# A list of include folders.
|
# A list of include folders.
|
||||||
includes: [include]
|
includes: [include]
|
||||||
# A map of C++20 modules in the format "module_name: [module_path, dependent files, ...]". Will only be used in C++20 or C++23 mode. The dependent files are any files that the module depends on, and are only used to determine whether the module needs to be recompiled.
|
# A map of C++20 modules in the format "module_name: [module_path, dependencies, ...]". Will only be used in C++20 or C++23 mode. The dependencies are any files that the module depends on, and are only used to determine whether the module needs to be recompiled.
|
||||||
modules:
|
modules:
|
||||||
BS.thread_pool: [modules/BS.thread_pool.cppm, include/BS_thread_pool.hpp]
|
BS.thread_pool: [modules/BS.thread_pool.cppm, include/BS_thread_pool.hpp]
|
||||||
# The output folder for the compiled files.
|
# The output folder for the compiled files.
|
||||||
output: build/
|
output: build/
|
||||||
# A list of arguments to pass to the program if running it after compilation.
|
# A list of arguments to pass to the program if running it after compilation.
|
||||||
pass_args: []
|
pass_args: []
|
||||||
# A map of paths to the standard library modules for each OS and compiler combination (C++23 only). The OS should be one of [Darwin, Linux, Windows]. This is currently only officially supported by MSVC with Microsoft STL and LLVM Clang (NOT Apple Clang) with LLVM libc++. It is not supported by GCC with any standard library, or any compiler with GNU libstdc++. Use "auto" to determine the path automatically if possible.
|
# A map of paths to the standard library modules for each OS and compiler combination (C++23 only). The OS should be one of [Darwin, Linux, Windows]. Use "auto" to determine the path automatically if possible.
|
||||||
std_module:
|
std_module:
|
||||||
Darwin:
|
Darwin:
|
||||||
clang++: auto
|
clang++: auto
|
||||||
Linux:
|
Linux:
|
||||||
clang++: auto
|
clang++: auto
|
||||||
|
g++: auto
|
||||||
Windows:
|
Windows:
|
||||||
cl: auto
|
cl: auto
|
||||||
clang++: auto
|
clang++: auto
|
||||||
|
g++: auto
|
||||||
|
|||||||
+599
-462
File diff suppressed because it is too large
Load Diff
@@ -7,9 +7,9 @@
|
|||||||
*
|
*
|
||||||
* @file BS.thread_pool.cppm
|
* @file BS.thread_pool.cppm
|
||||||
* @author Barak Shoshany (baraksh@gmail.com) (https://baraksh.com/)
|
* @author Barak Shoshany (baraksh@gmail.com) (https://baraksh.com/)
|
||||||
* @version 5.0.0
|
* @version 5.1.0
|
||||||
* @date 2024-12-19
|
* @date 2026-01-03
|
||||||
* @copyright Copyright (c) 2024 Barak Shoshany. Licensed under the MIT license. If you found this project useful, please consider starring it on GitHub! If you use this library in software of any kind, please provide a link to the GitHub repository https://github.com/bshoshany/thread-pool in the source code and documentation. If you use this library in published research, please cite it as follows: Barak Shoshany, "A C++17 Thread Pool for High-Performance Scientific Computing", doi:10.1016/j.softx.2024.101687, SoftwareX 26 (2024) 101687, arXiv:2105.00613
|
* @copyright Copyright (c) 2021-2026 Barak Shoshany. Licensed under the MIT license. If you found this project useful, please consider starring it on GitHub! If you use this library in software of any kind, please provide a link to the GitHub repository https://github.com/bshoshany/thread-pool in the source code and documentation. If you use this library in published research, please cite it as follows: Barak Shoshany, "A C++17 Thread Pool for High-Performance Scientific Computing", doi:10.1016/j.softx.2024.101687, SoftwareX 26 (2024) 101687, arXiv:2105.00613
|
||||||
*
|
*
|
||||||
* @brief `BS::thread_pool`: a fast, lightweight, modern, and easy-to-use C++17/C++20/C++23 thread pool library. This module file wraps the header file BS_thread_pool.hpp inside a C++20 module so it can be imported using `import BS.thread_pool`.
|
* @brief `BS::thread_pool`: a fast, lightweight, modern, and easy-to-use C++17/C++20/C++23 thread pool library. This module file wraps the header file BS_thread_pool.hpp inside a C++20 module so it can be imported using `import BS.thread_pool`.
|
||||||
*/
|
*/
|
||||||
@@ -17,18 +17,20 @@
|
|||||||
module;
|
module;
|
||||||
|
|
||||||
// A macro indicating to the library that it is being imported as a module, as well as the version of the module file, which must match the version of the header file.
|
// A macro indicating to the library that it is being imported as a module, as well as the version of the module file, which must match the version of the header file.
|
||||||
#define BS_THREAD_POOL_MODULE 5, 0, 0
|
#define BS_THREAD_POOL_MODULE 5, 1, 0
|
||||||
|
|
||||||
#include "BS_thread_pool.hpp"
|
#include "BS_thread_pool.hpp"
|
||||||
|
|
||||||
export module BS.thread_pool;
|
export module BS.thread_pool;
|
||||||
|
|
||||||
export namespace BS {
|
export namespace BS {
|
||||||
using BS::binary_semaphore;
|
|
||||||
using BS::common_index_type_t;
|
using BS::common_index_type_t;
|
||||||
using BS::counting_semaphore;
|
|
||||||
using BS::light_thread_pool;
|
using BS::light_thread_pool;
|
||||||
using BS::multi_future;
|
using BS::multi_future;
|
||||||
|
using BS::operator&;
|
||||||
|
using BS::operator^;
|
||||||
|
using BS::operator|;
|
||||||
|
using BS::operator~;
|
||||||
using BS::pause_thread_pool;
|
using BS::pause_thread_pool;
|
||||||
using BS::pr;
|
using BS::pr;
|
||||||
using BS::priority_t;
|
using BS::priority_t;
|
||||||
@@ -42,9 +44,12 @@ using BS::thread_pool_native_extensions;
|
|||||||
using BS::thread_pool_version;
|
using BS::thread_pool_version;
|
||||||
using BS::tp;
|
using BS::tp;
|
||||||
using BS::version;
|
using BS::version;
|
||||||
using BS::wait_deadlock;
|
|
||||||
using BS::wdc_thread_pool;
|
using BS::wdc_thread_pool;
|
||||||
|
|
||||||
|
#ifdef __cpp_exceptions
|
||||||
|
using BS::wait_deadlock;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef BS_THREAD_POOL_NATIVE_EXTENSIONS
|
#ifdef BS_THREAD_POOL_NATIVE_EXTENSIONS
|
||||||
using BS::get_os_process_affinity;
|
using BS::get_os_process_affinity;
|
||||||
using BS::get_os_process_priority;
|
using BS::get_os_process_priority;
|
||||||
|
|||||||
+1
-1
@@ -134,6 +134,7 @@ ignore = [
|
|||||||
"S603",
|
"S603",
|
||||||
"S607",
|
"S607",
|
||||||
"SIM108",
|
"SIM108",
|
||||||
|
"SIM112",
|
||||||
"SLF001",
|
"SLF001",
|
||||||
"T201",
|
"T201",
|
||||||
"TCH003",
|
"TCH003",
|
||||||
@@ -168,7 +169,6 @@ prefer-stubs = true
|
|||||||
py-version = "3.13"
|
py-version = "3.13"
|
||||||
recursive = false
|
recursive = false
|
||||||
source-roots = []
|
source-roots = []
|
||||||
suggestion-mode = true
|
|
||||||
unsafe-load-any-extension = false
|
unsafe-load-any-extension = false
|
||||||
|
|
||||||
[tool.pylint.basic]
|
[tool.pylint.basic]
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
"""
|
|
||||||
██████ ███████ ████████ ██ ██ ██████ ███████ █████ ██████ ██████ ██████ ██████ ██
|
|
||||||
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
||||||
██████ ███████ ██ ███████ ██████ █████ ███████ ██ ██ ██████ ██ ██ ██ ██ ██
|
|
||||||
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
||||||
██████ ███████ ██ ██ ██ ██ ██ ███████ ██ ██ ██████ ███████ ██ ██████ ██████ ███████
|
|
||||||
|
|
||||||
`BS::thread_pool`: a fast, lightweight, modern, and easy-to-use C++17/C++20/C++23 thread pool library
|
|
||||||
v5.0.0 (2024-12-19)
|
|
||||||
By Barak Shoshany <baraksh@gmail.com> <https://baraksh.com/>
|
|
||||||
Copyright (c) 2024 Barak Shoshany. Licensed under the MIT license. If you found this project useful, please consider starring it on GitHub! If you use this library in software of any kind, please provide a link to the GitHub repository https://github.com/bshoshany/thread-pool in the source code and documentation. If you use this library in published research, please cite it as follows: Barak Shoshany, "A C++17 Thread Pool for High-Performance Scientific Computing", doi:10.1016/j.softx.2024.101687, SoftwareX 26 (2024) 101687, arXiv:2105.00613
|
|
||||||
|
|
||||||
This Python script is used in the library's development environment to clear all files a folder. It is not part of the library itself.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import importlib
|
|
||||||
import importlib.util
|
|
||||||
import pathlib
|
|
||||||
import sys
|
|
||||||
from importlib.machinery import ModuleSpec
|
|
||||||
from types import ModuleType
|
|
||||||
|
|
||||||
send2trash_spec: ModuleSpec | None = importlib.util.find_spec("send2trash")
|
|
||||||
if send2trash_spec is not None:
|
|
||||||
# Install with `pip install send2trash`.
|
|
||||||
send2trash: ModuleType = importlib.import_module("send2trash")
|
|
||||||
|
|
||||||
def delete_files_in_folder(folder_path: pathlib.Path) -> None:
|
|
||||||
"""Recursively delete all files in a folder."""
|
|
||||||
for child in folder_path.iterdir():
|
|
||||||
if child.is_file():
|
|
||||||
send2trash.send2trash(paths=child)
|
|
||||||
else:
|
|
||||||
delete_files_in_folder(child)
|
|
||||||
send2trash.send2trash(folder_path)
|
|
||||||
else:
|
|
||||||
print("Note: Module send2trash not found; deleting files permanently.")
|
|
||||||
|
|
||||||
def delete_files_in_folder(folder_path: pathlib.Path) -> None:
|
|
||||||
"""Fallback function in case `send2trash` is not installed."""
|
|
||||||
for child in folder_path.iterdir():
|
|
||||||
if child.is_file():
|
|
||||||
child.unlink()
|
|
||||||
else:
|
|
||||||
delete_files_in_folder(child)
|
|
||||||
folder_path.rmdir()
|
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
|
||||||
_ = parser.add_argument("folder", help="the folder to clear (relative to this script's location)")
|
|
||||||
parsed_args: argparse.Namespace = parser.parse_args(args=None if len(sys.argv) > 1 else ["--help"])
|
|
||||||
|
|
||||||
folder: pathlib.Path = (pathlib.Path(__file__).parent / parsed_args.folder).resolve()
|
|
||||||
if not folder.exists():
|
|
||||||
print(f"Folder {folder} does not exist; creating empty.")
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
delete_files_in_folder(folder)
|
|
||||||
folder.mkdir()
|
|
||||||
print(f"Folder {folder} successfully cleared.")
|
|
||||||
except Exception as exc:
|
|
||||||
sys.exit(f"Error clearing folder {folder}: {exc}")
|
|
||||||
+537
-266
@@ -6,9 +6,9 @@
|
|||||||
██████ ███████ ██ ██ ██ ██ ██ ███████ ██ ██ ██████ ███████ ██ ██████ ██████ ███████
|
██████ ███████ ██ ██ ██ ██ ██ ███████ ██ ██ ██████ ███████ ██ ██████ ██████ ███████
|
||||||
|
|
||||||
`BS::thread_pool`: a fast, lightweight, modern, and easy-to-use C++17/C++20/C++23 thread pool library
|
`BS::thread_pool`: a fast, lightweight, modern, and easy-to-use C++17/C++20/C++23 thread pool library
|
||||||
v5.0.0 (2024-12-19)
|
v5.1.0 (2026-01-03)
|
||||||
By Barak Shoshany <baraksh@gmail.com> <https://baraksh.com/>
|
By Barak Shoshany <baraksh@gmail.com> <https://baraksh.com/>
|
||||||
Copyright (c) 2024 Barak Shoshany. Licensed under the MIT license. If you found this project useful, please consider starring it on GitHub! If you use this library in software of any kind, please provide a link to the GitHub repository https://github.com/bshoshany/thread-pool in the source code and documentation. If you use this library in published research, please cite it as follows: Barak Shoshany, "A C++17 Thread Pool for High-Performance Scientific Computing", doi:10.1016/j.softx.2024.101687, SoftwareX 26 (2024) 101687, arXiv:2105.00613
|
Copyright (c) 2021-2026 Barak Shoshany. Licensed under the MIT license. If you found this project useful, please consider starring it on GitHub! If you use this library in software of any kind, please provide a link to the GitHub repository https://github.com/bshoshany/thread-pool in the source code and documentation. If you use this library in published research, please cite it as follows: Barak Shoshany, "A C++17 Thread Pool for High-Performance Scientific Computing", doi:10.1016/j.softx.2024.101687, SoftwareX 26 (2024) 101687, arXiv:2105.00613
|
||||||
|
|
||||||
This Python script can be used to compile simple C++ programs (with only a few source and/or header files) using a variety of compilers, C++ standards, and other options. It also includes support for C++20 modules and C++23 Standard Library modules. It is used in the thread pool library's development environment to compile and run the test program using different compilers and C++ standards. It is not part of the library itself, but users of the library may find it useful, especially if they wish to use the library as a C++20 module.
|
This Python script can be used to compile simple C++ programs (with only a few source and/or header files) using a variety of compilers, C++ standards, and other options. It also includes support for C++20 modules and C++23 Standard Library modules. It is used in the thread pool library's development environment to compile and run the test program using different compilers and C++ standards. It is not part of the library itself, but users of the library may find it useful, especially if they wish to use the library as a C++20 module.
|
||||||
"""
|
"""
|
||||||
@@ -17,15 +17,16 @@ import argparse
|
|||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import platform
|
import platform
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
from enum import Enum
|
||||||
|
from typing import Any, Never, cast
|
||||||
|
|
||||||
import yaml # Install with `pip install pyyaml`.
|
import yaml # Install with `pip install pyyaml`.
|
||||||
|
|
||||||
separator: str = "=" * 60
|
|
||||||
|
|
||||||
|
|
||||||
class Args:
|
class Args:
|
||||||
"""A class to collect the command line arguments with proper type checking."""
|
"""A class to collect the command line arguments with proper type checking."""
|
||||||
@@ -35,10 +36,14 @@ class Args:
|
|||||||
self.files: list[str] = parsed_ns.files
|
self.files: list[str] = parsed_ns.files
|
||||||
self.arch: str = parsed_ns.arch
|
self.arch: str = parsed_ns.arch
|
||||||
self.as_module: bool = parsed_ns.as_module
|
self.as_module: bool = parsed_ns.as_module
|
||||||
|
self.clear_output: bool = parsed_ns.clear_output
|
||||||
self.compiler: str | None = parsed_ns.compiler
|
self.compiler: str | None = parsed_ns.compiler
|
||||||
self.define: list[str] = parsed_ns.define if parsed_ns.define is not None else []
|
self.define: list[str] = parsed_ns.define if parsed_ns.define is not None else []
|
||||||
|
self.deps: list[str] = parsed_ns.deps if parsed_ns.deps is not None else []
|
||||||
|
self.disable_exceptions: str | None = parsed_ns.disable_exceptions
|
||||||
self.flag: list[str] = parsed_ns.flag if parsed_ns.flag is not None else []
|
self.flag: list[str] = parsed_ns.flag if parsed_ns.flag is not None else []
|
||||||
self.ignore_yaml: bool = parsed_ns.ignore_yaml
|
self.force: bool = parsed_ns.force
|
||||||
|
self.ignore_config: bool = parsed_ns.ignore_config
|
||||||
self.include: list[str] = parsed_ns.include if parsed_ns.include is not None else []
|
self.include: list[str] = parsed_ns.include if parsed_ns.include is not None else []
|
||||||
self.module: list[str] = parsed_ns.module if parsed_ns.module is not None else []
|
self.module: list[str] = parsed_ns.module if parsed_ns.module is not None else []
|
||||||
self.output: str | None = parsed_ns.output
|
self.output: str | None = parsed_ns.output
|
||||||
@@ -46,81 +51,346 @@ class Args:
|
|||||||
self.run: bool = parsed_ns.run
|
self.run: bool = parsed_ns.run
|
||||||
self.std_module: str | None = parsed_ns.std_module
|
self.std_module: str | None = parsed_ns.std_module
|
||||||
self.std: str = parsed_ns.std
|
self.std: str = parsed_ns.std
|
||||||
|
self.try_all: bool = parsed_ns.try_all
|
||||||
self.type: str = parsed_ns.type
|
self.type: str = parsed_ns.type
|
||||||
self.verbose: bool = parsed_ns.verbose
|
self.verbose: bool = parsed_ns.verbose
|
||||||
|
|
||||||
|
|
||||||
# Parse the command-line arguments.
|
# Parse the command-line arguments.
|
||||||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||||
_ = parser.add_argument("files", nargs="+", help="the source file(s) to compile")
|
_ = parser.add_argument("files", action="store", nargs="*", help="the source file(s) to compile")
|
||||||
_ = parser.add_argument("-a", "--arch", choices=["amd64", "arm64"], default="amd64", help="the target architecture (MSVC only)")
|
_ = parser.add_argument("-a", "--arch", action="store", choices=["amd64", "arm64"], default="amd64", help="the target architecture (MSVC only)")
|
||||||
_ = parser.add_argument("-c", "--compiler", choices=["cl", "clang++", "g++"], help="which compiler to use (auto determined if not specified)")
|
_ = parser.add_argument("-b", "--clear-output", action="store_true", help="clear the output folder before compiling (if no source files are specified, just clear and exit)")
|
||||||
|
_ = parser.add_argument("-c", "--compiler", action="store", choices=["cl", "clang++", "g++"], help="which compiler to use (auto determined if not specified)")
|
||||||
_ = parser.add_argument("-d", "--define", action="append", help="macros to define (use multiple times if more than one) [in addition to those in compile_cpp.yaml]")
|
_ = parser.add_argument("-d", "--define", action="append", help="macros to define (use multiple times if more than one) [in addition to those in compile_cpp.yaml]")
|
||||||
|
_ = parser.add_argument("-e", "--force", action="store_true", help="force recompilation even if the compiled file is up to date")
|
||||||
_ = parser.add_argument("-f", "--flag", action="append", help="extra compiler flags to add (use multiple times if more than one) [in addition to those in compile_cpp.yaml]")
|
_ = parser.add_argument("-f", "--flag", action="append", help="extra compiler flags to add (use multiple times if more than one) [in addition to those in compile_cpp.yaml]")
|
||||||
_ = parser.add_argument("-g", "--ignore-yaml", action="store_true", help="ignore the compile_cpp.yaml file")
|
_ = parser.add_argument("-g", "--ignore-config", action="store_true", help="ignore the compile_cpp.yaml configuration file")
|
||||||
_ = parser.add_argument("-i", "--include", action="append", help="the include folder to use (use multiple times if more than one) [in addition to those in compile_cpp.yaml]")
|
_ = parser.add_argument("-i", "--include", action="append", help="the include folder to use (use multiple times if more than one) [in addition to those in compile_cpp.yaml]")
|
||||||
_ = parser.add_argument("-l", "--as-module", action="store_true", help="Compile file as module")
|
_ = parser.add_argument("-l", "--as-module", action="store_true", help="compile file as module")
|
||||||
_ = parser.add_argument("-m", "--module", action="append", help='C++20 module files to use if desired, in the format "module_name=module_file,dependent_files,..." (use multiple times if more than one) [in addition to those in compile_cpp.yaml]')
|
_ = parser.add_argument("-m", "--module", action="append", help='C++20 module files to use if desired, in the format "module_name=module_file,dependencies,..." (use multiple times if more than one) [in addition to those in compile_cpp.yaml]')
|
||||||
_ = parser.add_argument("-o", "--output", help="the output folder (end with / to create, taken from compile_cpp.yaml if not specified) and/or executable name (auto determined if not specified)")
|
_ = parser.add_argument("-n", "--deps", action="append", help="dependencies used to detect if recompilation is needed (use multiple times if more than one) [in addition to modules and those in compile_cpp.yaml]")
|
||||||
_ = parser.add_argument("-p", "--pass", action="append", dest="pass_args", help="pass command line arguments to the compiled program when running it, if -r is specified (use multiple times if more than one) [in addition to those in compile_cpp.yaml]")
|
_ = parser.add_argument("-o", "--output", action="store", help="the output folder (end with / to create, taken from compile_cpp.yaml if not specified) and/or binary name (auto determined if not specified)")
|
||||||
|
_ = parser.add_argument("-p", "--pass", action="append", dest="pass_args", help="pass command line arguments to the compiled program when running it, if -r/--run is specified (use multiple times if more than one) [in addition to those in compile_cpp.yaml]")
|
||||||
_ = parser.add_argument("-r", "--run", action="store_true", help="run the program after compiling it")
|
_ = parser.add_argument("-r", "--run", action="store_true", help="run the program after compiling it")
|
||||||
_ = parser.add_argument("-s", "--std", choices=["c++17", "c++20", "c++23"], default="c++23", help="which C++ standard to use")
|
_ = parser.add_argument("-s", "--std", action="store", choices=["c++17", "c++20", "c++23"], default="c++23", help="which C++ standard to use")
|
||||||
_ = parser.add_argument("-t", "--type", choices=["debug", "release"], default="debug", help="whether to compile in debug or release mode")
|
_ = parser.add_argument("-t", "--type", action="store", choices=["debug", "release"], default="debug", help="whether to compile in debug or release mode")
|
||||||
_ = parser.add_argument("-u", "--std-module", help="path to the standard library module (C++23 only, taken from compile_cpp.yaml if not specified, use 'auto' to auto-detect, 'disable' to explicitly disable)")
|
_ = parser.add_argument("-u", "--std-module", action="store", help="path to the standard library module (C++23 only, taken from compile_cpp.yaml if not specified, use 'auto' to auto-detect, 'disable' to explicitly disable)")
|
||||||
_ = parser.add_argument("-v", "--verbose", action="store_true", help="whether to print this script's diagnostic messages")
|
_ = parser.add_argument("-v", "--verbose", action="store_true", help="whether to print this script's diagnostic messages")
|
||||||
|
_ = parser.add_argument("-x", "--disable-exceptions", action="store", choices=["true", "false"], help="whether to disable exceptions [overrides compile_cpp.yaml]")
|
||||||
|
_ = parser.add_argument("-y", "--try-all", action="store_true", help="test compilation using all possible combinations of available compilers and C++ standards (also runs each compiled program if -r/--run is specified)")
|
||||||
args = Args(parser.parse_args(args=None if len(sys.argv) > 1 else ["--help"]))
|
args = Args(parser.parse_args(args=None if len(sys.argv) > 1 else ["--help"]))
|
||||||
|
|
||||||
|
|
||||||
def print_if_verbose(message: str) -> None:
|
class ANSI(Enum):
|
||||||
"""Print a message, but only if the verbose flag is set."""
|
"""Enumeration of ANSI color codes for terminal output."""
|
||||||
|
|
||||||
|
reset = 0
|
||||||
|
bold = 1
|
||||||
|
dim = 2
|
||||||
|
italic = 3
|
||||||
|
underline = 4
|
||||||
|
invert = 7
|
||||||
|
strike = 9
|
||||||
|
double_underline = 21
|
||||||
|
fg_black = 30
|
||||||
|
fg_red = 31
|
||||||
|
fg_green = 32
|
||||||
|
fg_yellow = 33
|
||||||
|
fg_blue = 34
|
||||||
|
fg_magenta = 35
|
||||||
|
fg_cyan = 36
|
||||||
|
fg_white = 37
|
||||||
|
bg_black = 40
|
||||||
|
bg_red = 41
|
||||||
|
bg_green = 42
|
||||||
|
bg_yellow = 43
|
||||||
|
bg_blue = 44
|
||||||
|
bg_magenta = 45
|
||||||
|
bg_cyan = 46
|
||||||
|
bg_white = 47
|
||||||
|
fg_bright_black = 90
|
||||||
|
fg_bright_red = 91
|
||||||
|
fg_bright_green = 92
|
||||||
|
fg_bright_yellow = 93
|
||||||
|
fg_bright_blue = 94
|
||||||
|
fg_bright_magenta = 95
|
||||||
|
fg_bright_cyan = 96
|
||||||
|
fg_bright_white = 97
|
||||||
|
bg_bright_black = 100
|
||||||
|
bg_bright_red = 101
|
||||||
|
bg_bright_green = 102
|
||||||
|
bg_bright_yellow = 103
|
||||||
|
bg_bright_blue = 104
|
||||||
|
bg_bright_magenta = 105
|
||||||
|
bg_bright_cyan = 106
|
||||||
|
bg_bright_white = 107
|
||||||
|
|
||||||
|
|
||||||
|
ANSI_INFO = ANSI.fg_bright_blue
|
||||||
|
ANSI_ERROR = ANSI.fg_bright_red
|
||||||
|
ANSI_SUCCESS = ANSI.fg_bright_green
|
||||||
|
ANSI_SEPARATOR = ANSI.fg_bright_yellow
|
||||||
|
ANSI_TRY_ALL = ANSI.fg_bright_magenta
|
||||||
|
|
||||||
|
|
||||||
|
no_color: bool = os.environ.get("NO_COLOR", "") != ""
|
||||||
|
|
||||||
|
|
||||||
|
def print_ansi(message: str, *codes: ANSI) -> None:
|
||||||
|
"""Print a message. Uses the given ANSI codes if specified. Does not add newline. Does not print color if the `NO_COLOR` environment variable is set."""
|
||||||
|
if len(codes) > 0 and not no_color:
|
||||||
|
seq = ";".join(str(c.value) for c in codes)
|
||||||
|
print(f"\033[{seq}m{message}\033[{ANSI.reset.value}m", end="")
|
||||||
|
else:
|
||||||
|
print(message, end="")
|
||||||
|
|
||||||
|
|
||||||
|
def print_if_verbose(message: str, *codes: ANSI) -> None:
|
||||||
|
"""Print a message followed by a newline, but only if the verbose flag is set. Uses the given ANSI codes if specified."""
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print(message)
|
print_ansi(message + "\n", *codes)
|
||||||
|
|
||||||
|
|
||||||
|
def print_separator() -> None:
|
||||||
|
"""Print a separator line, but only if the verbose flag is set."""
|
||||||
|
print_if_verbose("=" * 60, ANSI_SEPARATOR)
|
||||||
|
|
||||||
|
|
||||||
|
def print_key_values(key: str, values: list[str], length: int) -> None:
|
||||||
|
"""Print a key-value pair with the key left-aligned to the given length, but only if the verbose flag is set."""
|
||||||
|
if args.verbose:
|
||||||
|
print_ansi((key + ":").ljust(length), ANSI.fg_bright_white, ANSI.bold)
|
||||||
|
if len(values) == 0:
|
||||||
|
print("<None>")
|
||||||
|
else:
|
||||||
|
print(values[0])
|
||||||
|
for value in values[1:]:
|
||||||
|
print(" " * length + f"{value}")
|
||||||
|
|
||||||
|
|
||||||
|
def print_error_and_exit(message: str) -> Never:
|
||||||
|
"""Print an error message followed by a newline in red and exit."""
|
||||||
|
print_ansi(message + "\n", ANSI_ERROR)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def relative_or_full_path(path: pathlib.Path) -> pathlib.Path:
|
||||||
|
"""If the path is relative to the current working directory, return it as a relative path; otherwise, return it as a full path."""
|
||||||
|
return path.relative_to(pathlib.Path.cwd()) if path.is_relative_to(pathlib.Path.cwd()) else path
|
||||||
|
|
||||||
|
|
||||||
|
def parse_llvm_version(path_str: str) -> tuple[int, ...] | None:
|
||||||
|
"""Extract the LLVM version from a path and returns it as a tuple of integers."""
|
||||||
|
match: re.Match[str] | None = re.search(r"/llvm[-/](\d+(?:\.\d+)*)", path_str)
|
||||||
|
if match is None:
|
||||||
|
return None
|
||||||
|
return tuple(int(part) for part in match.group(1).split("."))
|
||||||
|
|
||||||
|
|
||||||
|
def get_llvm_std_module(search: str) -> str | None:
|
||||||
|
"""Get the path to the LLVM standard library module on Linux or macOS. If multiple paths are found, return the one with the latest LLVM version."""
|
||||||
|
try:
|
||||||
|
llvm_path: str = subprocess.check_output([f"find {search} -name std.cppm"], text=True, shell=True).strip()
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
llvm_path: str = ""
|
||||||
|
all_paths: list[str] = [line for line in llvm_path.splitlines() if line.strip()]
|
||||||
|
if len(all_paths) == 0:
|
||||||
|
return None
|
||||||
|
return max(all_paths, key=lambda p: parse_llvm_version(p) or (0,))
|
||||||
|
|
||||||
|
|
||||||
|
def find_vs_path() -> pathlib.Path | None:
|
||||||
|
"""Find the Visual Studio installation path, if it exists."""
|
||||||
|
if platform.system() != "Windows":
|
||||||
|
return None
|
||||||
|
pf86: str = os.environ.get("ProgramFiles(x86)", r"C:\Program Files (x86)")
|
||||||
|
pf: str = os.environ.get("ProgramFiles", r"C:\Program Files")
|
||||||
|
try_paths: list[pathlib.Path] = [pathlib.Path(p) / "Microsoft Visual Studio" / "Installer" / "vswhere.exe" for p in [pf86, pf]]
|
||||||
|
vswhere: pathlib.Path | None = next((p for p in try_paths if p.exists()), None)
|
||||||
|
if vswhere is None:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
install_root: str = subprocess.check_output(
|
||||||
|
[
|
||||||
|
str(vswhere),
|
||||||
|
"-latest",
|
||||||
|
"-property",
|
||||||
|
"installationPath",
|
||||||
|
],
|
||||||
|
text=True,
|
||||||
|
).strip()
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return None
|
||||||
|
if install_root == "":
|
||||||
|
return None
|
||||||
|
return pathlib.Path(install_root)
|
||||||
|
|
||||||
|
|
||||||
|
def get_module_flags(name: str, module_output_path: pathlib.Path) -> list[str]:
|
||||||
|
"""Get the appropriate flags to import a module with the given name from the given output path."""
|
||||||
|
if compiler == "cl":
|
||||||
|
return ["/reference", f"{name}={module_output_path.resolve()}", *([str(build_folder / f"{module_output_path.stem}.obj")] if (name != "std" or not args.as_module) else [])]
|
||||||
|
if compiler == "clang++":
|
||||||
|
return [f"-fmodule-file={name}={module_output_path.resolve()}"]
|
||||||
|
# Otherwise, compiler == "g++".
|
||||||
|
return ["-fmodules", f"-fmodule-mapper=|@g++-mapper-server -r{build_folder}"]
|
||||||
|
|
||||||
|
|
||||||
|
def compile_module(name: str, paths: list[pathlib.Path], module_output_path: pathlib.Path) -> bool:
|
||||||
|
"""Compile a module with the given name. The first path in `paths` is the module file, and the rest are its dependencies. Returns True if the module was recompiled, False if it was up to date."""
|
||||||
|
module_file: pathlib.Path = paths[0]
|
||||||
|
if module_output_path.exists():
|
||||||
|
module_output_mod: float = module_output_path.stat().st_mtime
|
||||||
|
if not any((path.exists() and path.stat().st_mtime > module_output_mod) for path in paths):
|
||||||
|
print_if_verbose(f'Module "{name}" is up to date, skipping compilation.', ANSI_INFO)
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
module_command: list[str] = [
|
||||||
|
sys.executable,
|
||||||
|
str(pathlib.Path(__file__).resolve()),
|
||||||
|
# In the special case of GCC and the `std` module, `bits/std.cc` must be entered without the full path.
|
||||||
|
str(module_file) if not (compiler == "g++" and name == "std") else gcc_std_path,
|
||||||
|
f"--output={module_output_path.resolve()}",
|
||||||
|
f"--arch={args.arch}",
|
||||||
|
f"--compiler={compiler}",
|
||||||
|
f"--std={args.std}",
|
||||||
|
f"--type={args.type}",
|
||||||
|
# Note: Not adding the extra options from the configuration file, since they will be added by the script anyway.
|
||||||
|
*[f"--define={define}" for define in args.define],
|
||||||
|
*[f"--include={include}" for include in args.include],
|
||||||
|
*[f"--flag={flag}" for flag in args.flag],
|
||||||
|
# For the `std` module in GCC, we also need to add `-fsearch-include-path`.
|
||||||
|
*(["--flag=-fsearch-include-path"] if (compiler == "g++" and name == "std") else []),
|
||||||
|
# If compiling the `std` module itself, we need to pass `-u=disable` to avoid infinite recursion. Otherwise, we pass along the specified module path if it exists.
|
||||||
|
*(["--std-module=disable"] if name == "std" else [f"--std-module={std_module}"] if std_module is not None else []),
|
||||||
|
"--as-module",
|
||||||
|
*(["--verbose"] if args.verbose else []),
|
||||||
|
*(["--disable-exceptions=true"] if disable_exceptions else ["--disable-exceptions=false"]),
|
||||||
|
]
|
||||||
|
print_separator()
|
||||||
|
print_if_verbose(f'Compiling module "{name}" with command: {subprocess.list2cmdline(module_command)}', ANSI_INFO)
|
||||||
|
_ = sys.stdout.flush()
|
||||||
|
module_result = subprocess.run(
|
||||||
|
args=module_command,
|
||||||
|
check=False,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
if module_result.returncode != 0:
|
||||||
|
print_error_and_exit(f"Module compilation failed with return code: {module_result.returncode}.")
|
||||||
|
except Exception as exc:
|
||||||
|
print_error_and_exit(f"Could not compile module due to exception: {exc}.")
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
# Collect the full path(s) to the source file(s).
|
# Collect the full path(s) to the source file(s).
|
||||||
source_paths: list[pathlib.Path] = [pathlib.Path(file).resolve() for file in args.files]
|
source_paths: list[pathlib.Path] = [pathlib.Path(file) for file in args.files]
|
||||||
|
|
||||||
|
# If the `try_all` flag is set, run this script recursively using all possible combinations of compilers and C++ standards available in the system.
|
||||||
|
if args.try_all:
|
||||||
|
if "-c" in sys.argv or "--compiler" in sys.argv:
|
||||||
|
print_error_and_exit("Error: The -y/--try-all flag cannot be used together with the -c/--compiler flag.")
|
||||||
|
if "-s" in sys.argv or "--std" in sys.argv:
|
||||||
|
print_error_and_exit("Error: The -y/--try-all flag cannot be used together with the -s/--std flag.")
|
||||||
|
# We pass all the arguments to the child processes except for the one that enables this mode, to avoid infinite recursion.
|
||||||
|
child_args: list[str] = [arg for arg in sys.argv[1:] if arg not in ("-y", "--try-all")]
|
||||||
|
|
||||||
|
# Determine which compilers are available.
|
||||||
|
compilers: list[str] = []
|
||||||
|
if find_vs_path() is not None:
|
||||||
|
compilers.append("cl")
|
||||||
|
if shutil.which("clang++") is not None:
|
||||||
|
compilers.append("clang++")
|
||||||
|
# On macOS, g++ is by default just an alias for clang++, so we skip it.
|
||||||
|
if shutil.which("g++") is not None and platform.system() != "Darwin":
|
||||||
|
compilers.append("g++")
|
||||||
|
|
||||||
|
# Compile using all available compilers using all relevant C++ standards.
|
||||||
|
standards: list[str] = ["c++17", "c++20", "c++23"]
|
||||||
|
workspace_path: pathlib.Path = pathlib.Path(__file__).parent.parent.resolve()
|
||||||
|
try:
|
||||||
|
compile_start: float = time.perf_counter()
|
||||||
|
for compiler in compilers:
|
||||||
|
for std in standards:
|
||||||
|
warnings_as_errors: list[str] = ["-f/WX"] if compiler == "cl" else ["-f-Werror"]
|
||||||
|
command: list[str] = [
|
||||||
|
sys.executable,
|
||||||
|
str(pathlib.Path(__file__).resolve()),
|
||||||
|
"-c",
|
||||||
|
compiler,
|
||||||
|
"-s",
|
||||||
|
std,
|
||||||
|
*warnings_as_errors,
|
||||||
|
*child_args,
|
||||||
|
]
|
||||||
|
print_if_verbose(f"Compiling with {compiler} using {std.upper()} standard with command: {subprocess.list2cmdline(command)}", ANSI_TRY_ALL)
|
||||||
|
compile_result = subprocess.run(
|
||||||
|
args=command,
|
||||||
|
check=False,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
if compile_result.returncode != 0:
|
||||||
|
print_if_verbose("Compilation failed, aborting!", ANSI_TRY_ALL)
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as exc:
|
||||||
|
print_if_verbose(f"Could not compile due to exception: {exc}, aborting!", ANSI_TRY_ALL)
|
||||||
|
sys.exit(1)
|
||||||
|
print_if_verbose(f"All compilations completed successfully in {time.perf_counter() - compile_start:.2f} seconds.", ANSI_TRY_ALL)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
# Determine the compiler if it is not given.
|
# Determine the compiler if it is not given.
|
||||||
compiler: str = ""
|
compiler: str = ""
|
||||||
vs_pwsh_path: str = r"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1"
|
vs_path: pathlib.Path | None = find_vs_path()
|
||||||
if args.compiler is not None:
|
if args.compiler is not None:
|
||||||
compiler = args.compiler
|
compiler = args.compiler
|
||||||
else: # noqa: PLR5501
|
elif platform.system() == "Windows":
|
||||||
# On Windows, we default to MSVC if the Visual Studio Developer PowerShell script exists, otherwise we fall back to Clang, and then GCC.
|
# On Windows, we default to MSVC if the Visual Studio installation path exists, otherwise we fall back to Clang, and then GCC.
|
||||||
if platform.system() == "Windows":
|
if vs_path is not None and vs_path.exists():
|
||||||
if pathlib.Path(vs_pwsh_path).exists():
|
compiler = "cl"
|
||||||
compiler = "cl"
|
elif shutil.which("clang++") is not None:
|
||||||
elif shutil.which("clang++") is not None:
|
|
||||||
compiler = "clang++"
|
|
||||||
elif shutil.which("g++") is not None:
|
|
||||||
compiler = "g++"
|
|
||||||
# On Linux, we default to GCC if it is available, otherwise we fall back to Clang.
|
|
||||||
elif platform.system() == "Linux":
|
|
||||||
if shutil.which("g++") is not None:
|
|
||||||
compiler = "g++"
|
|
||||||
elif shutil.which("clang++") is not None:
|
|
||||||
compiler = "clang++"
|
|
||||||
# On macOS, we just check if Clang is available.
|
|
||||||
elif platform.system() == "Darwin" and shutil.which("clang++") is not None:
|
|
||||||
compiler = "clang++"
|
compiler = "clang++"
|
||||||
|
elif shutil.which("g++") is not None:
|
||||||
|
compiler = "g++"
|
||||||
|
elif platform.system() == "Linux":
|
||||||
|
# On Linux, we default to GCC if it is available, otherwise we fall back to Clang.
|
||||||
|
if shutil.which("g++") is not None:
|
||||||
|
compiler = "g++"
|
||||||
|
elif shutil.which("clang++") is not None:
|
||||||
|
compiler = "clang++"
|
||||||
|
elif platform.system() == "Darwin" and shutil.which("clang++") is not None:
|
||||||
|
# On macOS, we just check if Clang is available.
|
||||||
|
compiler = "clang++"
|
||||||
if compiler == "":
|
if compiler == "":
|
||||||
sys.exit("Error: No compiler found!")
|
print_error_and_exit("Error: No compiler found!")
|
||||||
|
|
||||||
# If a file named `compile_cpp.yaml` exists in the current working directory, read the configuration from it. All options are added to those from the command line, except the output file/folder and path to the standard library module, which are only used if not provided in the command line. Note that all folders should be specified relative to the current working directory.
|
# If a file named `compile_cpp.yaml` exists in the current working directory, read the configuration from it. All options are added to those from the command line, except the output file/folder and path to the standard library module, which are only used if not provided in the command line. Note that all folders should be specified relative to the current working directory.
|
||||||
defines: list[str] = args.define[:]
|
defines: list[str] = args.define[:]
|
||||||
|
deps: list[str] = args.deps[:]
|
||||||
|
disable_exceptions: bool = args.disable_exceptions == "true"
|
||||||
flags: list[str] = args.flag[:]
|
flags: list[str] = args.flag[:]
|
||||||
includes: list[str] = args.include[:]
|
includes: list[str] = args.include[:]
|
||||||
modules: dict[str, list[str]] = {name: files.split(",") for module in args.module for name, files in (module.split("="),)}
|
try:
|
||||||
|
modules: dict[str, list[str]] = {name: files.split(",") for module in args.module for name, files in (module.split("="),)}
|
||||||
|
except ValueError:
|
||||||
|
print_error_and_exit('Error: Module specification must be in the format "module_name=module_file,dependencies,...".')
|
||||||
output: str | None = args.output
|
output: str | None = args.output
|
||||||
pass_args: list[str] = args.pass_args[:]
|
pass_args: list[str] = args.pass_args[:]
|
||||||
compile_yaml: pathlib.Path = pathlib.Path.cwd() / "compile_cpp.yaml"
|
|
||||||
std_module: str | None = args.std_module
|
std_module: str | None = args.std_module
|
||||||
|
|
||||||
if not args.ignore_yaml and compile_yaml.exists():
|
compile_yaml: pathlib.Path = pathlib.Path.cwd() / "compile_cpp.yaml"
|
||||||
|
if not args.ignore_config and compile_yaml.exists():
|
||||||
with compile_yaml.open("r") as file:
|
with compile_yaml.open("r") as file:
|
||||||
compile_config = yaml.safe_load(file)
|
raw_config: dict[str, Any] | Any = yaml.safe_load(file) or {}
|
||||||
|
if not isinstance(raw_config, dict):
|
||||||
|
print_error_and_exit("Error: compile_cpp.yaml must be a dictionary of options.")
|
||||||
|
compile_config = cast("dict[str, Any]", raw_config)
|
||||||
if "defines" in compile_config:
|
if "defines" in compile_config:
|
||||||
defines.extend(compile_config["defines"])
|
defines.extend(compile_config["defines"])
|
||||||
|
if "deps" in compile_config:
|
||||||
|
deps.extend(compile_config["deps"])
|
||||||
|
if args.disable_exceptions is None and "disable_exceptions" in compile_config:
|
||||||
|
disable_exceptions = compile_config["disable_exceptions"] is True
|
||||||
if "flags" in compile_config and compiler in compile_config["flags"]:
|
if "flags" in compile_config and compiler in compile_config["flags"]:
|
||||||
flags.extend(compile_config["flags"][compiler])
|
flags.extend(compile_config["flags"][compiler])
|
||||||
if "includes" in compile_config:
|
if "includes" in compile_config:
|
||||||
@@ -134,21 +404,75 @@ if not args.ignore_yaml and compile_yaml.exists():
|
|||||||
if std_module is None and "std_module" in compile_config and platform.system() in compile_config["std_module"] and compiler in compile_config["std_module"][platform.system()] and len(compile_config["std_module"][platform.system()][compiler]) > 0:
|
if std_module is None and "std_module" in compile_config and platform.system() in compile_config["std_module"] and compiler in compile_config["std_module"][platform.system()] and len(compile_config["std_module"][platform.system()][compiler]) > 0:
|
||||||
std_module = compile_config["std_module"][platform.system()][compiler]
|
std_module = compile_config["std_module"][platform.system()][compiler]
|
||||||
|
|
||||||
# Importing the C++ Standard Library is only available in C++23 mode, and currently only officially supported by MSVC and Clang. If "disable" is specified for the standard library module, we skip it; this is used to avoid infinite recursion.
|
# Determine the name of the binary file and the build folder.
|
||||||
use_std_module: bool = not (std_module is None or std_module == "disable" or args.std != "c++23" or compiler not in ["cl", "clang++"])
|
binary_path: pathlib.Path | None = None
|
||||||
|
build_folder: pathlib.Path
|
||||||
|
auto_binary: bool = False
|
||||||
|
if output is not None:
|
||||||
|
# Calculate the output path relative to the current working directory. Note that if the path is absolute, `pathlib` will automatically use the absolute path instead of a relative path.
|
||||||
|
output_path: pathlib.Path = (pathlib.Path.cwd() / output).resolve()
|
||||||
|
if output.endswith(("/", "\\")) or output_path.is_dir():
|
||||||
|
# If the output path is a directory, we use it as the build folder, and automatically determine the name of the binary file.
|
||||||
|
build_folder = output_path.resolve()
|
||||||
|
auto_binary = True
|
||||||
|
elif output_path.is_absolute():
|
||||||
|
# If the output path is an absolute path to a file, the build folder is the file's folder.
|
||||||
|
build_folder = output_path.parent.resolve()
|
||||||
|
binary_path = output_path
|
||||||
|
else:
|
||||||
|
# If the output path is just a file name, the build folder is the current working directory by default.
|
||||||
|
build_folder = pathlib.Path.cwd()
|
||||||
|
binary_path = build_folder / output_path
|
||||||
|
else:
|
||||||
|
# If there is no output path at all, the build folder is the current working directory by default, and we automatically determine the name of the binary file.
|
||||||
|
build_folder = pathlib.Path.cwd()
|
||||||
|
auto_binary = True
|
||||||
|
|
||||||
|
# Clear and recreate the build folder if requested.
|
||||||
|
if args.clear_output:
|
||||||
|
if build_folder == pathlib.Path.cwd():
|
||||||
|
print_error_and_exit("Error: Cannot clear the output path if it is the current working directory.")
|
||||||
|
if build_folder.exists():
|
||||||
|
print_if_verbose(f"Clearing output folder: {relative_or_full_path(build_folder)}", ANSI_INFO)
|
||||||
|
shutil.rmtree(build_folder)
|
||||||
|
pathlib.Path(build_folder).mkdir(exist_ok=True, parents=True)
|
||||||
|
print_if_verbose("Cleared successfully!", ANSI_SUCCESS)
|
||||||
|
else:
|
||||||
|
print_if_verbose(f"Creating empty output folder: {relative_or_full_path(build_folder)}", ANSI_INFO)
|
||||||
|
pathlib.Path(build_folder).mkdir(exist_ok=True, parents=True)
|
||||||
|
print_if_verbose("Created successfully!", ANSI_SUCCESS)
|
||||||
|
if len(source_paths) == 0:
|
||||||
|
# If no source files are specified, just clear and exit.
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
# Otherwise, just create the build folder if it does not exist.
|
||||||
|
pathlib.Path(build_folder).mkdir(exist_ok=True, parents=True)
|
||||||
|
|
||||||
|
# Add the appropriate flags to disable exceptions if requested.
|
||||||
|
if disable_exceptions:
|
||||||
|
if compiler == "cl":
|
||||||
|
flags.extend(["/EHs-c-", "/D_HAS_EXCEPTIONS=0"])
|
||||||
|
else:
|
||||||
|
flags.append("-fno-exceptions")
|
||||||
|
elif compiler == "cl":
|
||||||
|
flags.append("/EHsc")
|
||||||
|
|
||||||
|
# Importing the C++ Standard Library is only available in C++23 mode. If "disable" is specified for the standard library module, we skip it; this is used to avoid infinite recursion.
|
||||||
|
use_std_module: bool = not (std_module is None or std_module == "disable" or args.std != "c++23")
|
||||||
|
|
||||||
if use_std_module and std_module is not None:
|
if use_std_module and std_module is not None:
|
||||||
modules = {"std": [std_module], **modules}
|
modules = {"std": [std_module], **modules}
|
||||||
|
|
||||||
# Figure out the path to the MSVC or Clang std module, if relevant.
|
# Figure out the path to the std module, if relevant.
|
||||||
|
gcc_std_path: str = "bits/std.cc"
|
||||||
if use_std_module and "std" in modules and modules["std"][0].strip() == "auto":
|
if use_std_module and "std" in modules and modules["std"][0].strip() == "auto":
|
||||||
success: bool = False
|
success: bool = False
|
||||||
if platform.system() == "Windows" and compiler == "cl":
|
if platform.system() == "Windows" and compiler == "cl" and vs_path is not None:
|
||||||
vc_version_path: pathlib.Path = pathlib.Path(r"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt")
|
vc_version_path: pathlib.Path = vs_path / "VC" / "Auxiliary" / "Build" / "Microsoft.VCToolsVersion.default.txt"
|
||||||
if vc_version_path.exists():
|
if vc_version_path.exists():
|
||||||
with vc_version_path.open("r", encoding="utf-8") as vc_version_file:
|
with vc_version_path.open("r", encoding="utf-8") as vc_version_file:
|
||||||
vc_version: str = vc_version_file.read().strip()
|
vc_version: str = vc_version_file.read().strip()
|
||||||
vc_tools_path: str = rf"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\{vc_version}"
|
vc_tools_path: pathlib.Path = vs_path / "VC" / "Tools" / "MSVC" / vc_version
|
||||||
modules["std"][0] = rf"{vc_tools_path}\modules\std.ixx"
|
modules["std"][0] = rf"{vc_tools_path}\modules\std.ixx"
|
||||||
success = True
|
success = True
|
||||||
elif compiler == "clang++":
|
elif compiler == "clang++":
|
||||||
@@ -162,248 +486,195 @@ if use_std_module and "std" in modules and modules["std"][0].strip() == "auto":
|
|||||||
modules["std"][0] = str(std_path.absolute())
|
modules["std"][0] = str(std_path.absolute())
|
||||||
success = True
|
success = True
|
||||||
elif platform.system() == "Darwin":
|
elif platform.system() == "Darwin":
|
||||||
# On macOS, the `std` module should be at `/usr/local/Cellar/llvm/<LLVM full version>/share/libc++/v1/std.cppm`. We use `find` to locate it without needing to know the exact LLVM version.
|
# On macOS, the `std` module should be at `/usr/local/Cellar/llvm/<LLVM full version>/share/libc++/v1/std.cppm`.
|
||||||
llvm_path: str = subprocess.check_output(["find", "/usr/local/Cellar/llvm", "-name", "std.cppm"], text=True).strip()
|
llvm_std_path: str | None = get_llvm_std_module("/usr/local/Cellar/llvm")
|
||||||
if llvm_path:
|
if llvm_std_path:
|
||||||
modules["std"][0] = llvm_path
|
modules["std"][0] = llvm_std_path
|
||||||
success = True
|
success = True
|
||||||
elif platform.system() == "Linux":
|
elif platform.system() == "Linux":
|
||||||
# On Linux, the `std` module should be at `/usr/lib/llvm-<LLVM major version>/share/libc++/v1/std.cppm`. We use `find` to locate it without needing to know the exact LLVM version.
|
# On Linux, the `std` module should be at `/usr/lib/llvm-<LLVM major version>/share/libc++/v1/std.cppm`.
|
||||||
llvm_path: str = subprocess.check_output(["find", "/usr/lib", "-name", "std.cppm"], text=True).strip()
|
llvm_std_path: str | None = get_llvm_std_module("/usr/lib/llvm-*")
|
||||||
if llvm_path:
|
if llvm_std_path:
|
||||||
modules["std"][0] = llvm_path
|
modules["std"][0] = llvm_std_path
|
||||||
success = True
|
success = True
|
||||||
|
else: # compiler == "g++"
|
||||||
|
# In GCC the module file is always at `bits/std.cc`.
|
||||||
|
modules["std"][0] = gcc_std_path
|
||||||
|
success = True
|
||||||
if not success:
|
if not success:
|
||||||
sys.exit('Error: "auto" specified for the standard library module path, but the script could not locate it. Please specify the path manually.')
|
print_error_and_exit('Error: "auto" specified for the standard library module path, but the script could not locate it. Please specify the path manually.')
|
||||||
|
|
||||||
# Determine the name of the executable file and the build folder.
|
# Determine the appropriate extension for modules.
|
||||||
executable_path: pathlib.Path | None = None
|
module_extension: str = ""
|
||||||
build_folder: pathlib.Path
|
if compiler == "cl":
|
||||||
auto_executable: bool = False
|
module_extension = ".ifc"
|
||||||
if output is not None:
|
elif compiler == "clang++":
|
||||||
# Calculate the output path relative to the current working directory. Note that if the path is absolute, `pathlib` will automatically use the absolute path instead of a relative path.
|
module_extension = ".pcm"
|
||||||
output_path: pathlib.Path = (pathlib.Path.cwd() / output).resolve()
|
else: # compiler == "g++"
|
||||||
if output.endswith(("/", "\\")) or output_path.is_dir():
|
# For GCC, the extension is `.gcm`, but we do not have control over that; however, we also create an object file with the `.o` extension so we can check if the module is up to date (see below).
|
||||||
# If the output path is a directory, we use it as the build folder, and automatically determine the name of the executable file.
|
module_extension = ".o"
|
||||||
build_folder = output_path.resolve()
|
|
||||||
auto_executable = True
|
|
||||||
elif output_path.is_absolute():
|
|
||||||
# If the output path is an absolute path to a file, the build folder is the file's folder.
|
|
||||||
build_folder = output_path.parent.resolve()
|
|
||||||
executable_path = output_path
|
|
||||||
else:
|
|
||||||
# If the output path is just a file name, the build folder is the current working directory by default.
|
|
||||||
build_folder = pathlib.Path.cwd()
|
|
||||||
executable_path = build_folder / output_path
|
|
||||||
else:
|
|
||||||
# If there is no output path at all, the build folder is the current working directory by default, and we automatically determine the name of the executable file.
|
|
||||||
build_folder = pathlib.Path.cwd()
|
|
||||||
auto_executable = True
|
|
||||||
|
|
||||||
# If the user did not provide an output file name, we use the name of the first source file, appending the compiler, mode, and C++ standard.
|
# If we are compiling as a module, add the appropriate flags.
|
||||||
|
if args.as_module:
|
||||||
|
if compiler == "cl":
|
||||||
|
flags.extend(["/interface", "/TP", "/c"])
|
||||||
|
elif compiler == "clang++":
|
||||||
|
flags.extend(["--precompile", "-Wno-include-angled-in-module-purview", "-Wno-reserved-module-identifier", "-xc++-module"])
|
||||||
|
else: # compiler == "g++"
|
||||||
|
# Note: Creating an object file can be disabled with `-fmodule-only`, and it doesn't seem like the object file is actually needed, only the `.gcm` file. However, we create the object file anyway so we can check if the module is up to date, since there appears to be no way to control the name of the `.gcm` file.
|
||||||
|
flags.extend(["-fmodules", "-c", f"-fmodule-mapper=|@g++-mapper-server -r{build_folder}", "-xc++"])
|
||||||
|
|
||||||
|
# If the user did not provide an output file name, we use the name of the first source file, appending the compiler, mode, and C++ standard, as well as the appropriate extension.
|
||||||
short_compiler: str = "clang" if compiler == "clang++" else "gcc" if compiler == "g++" else "msvc"
|
short_compiler: str = "clang" if compiler == "clang++" else "gcc" if compiler == "g++" else "msvc"
|
||||||
suffix: str = f"{args.type}-{short_compiler}-cpp{args.std[-2:]}"
|
suffix: str = f"{args.type}-{short_compiler}-cpp{args.std[-2:]}"
|
||||||
if auto_executable:
|
if auto_binary:
|
||||||
extension: str = ".exe" if platform.system() == "Windows" else ""
|
extension: str = module_extension if args.as_module else ".exe" if platform.system() == "Windows" else ""
|
||||||
executable: str = f"{source_paths[0].stem}_{suffix}{extension}"
|
module_indicator: str = "module_" if args.as_module else ""
|
||||||
executable_path = build_folder / executable
|
binary_name: str = f"{source_paths[0].stem}_{module_indicator}{suffix}{extension}"
|
||||||
if executable_path is None:
|
binary_path = build_folder / binary_name
|
||||||
sys.exit("Error: Could not determine executable file!")
|
if binary_path is None:
|
||||||
|
print_error_and_exit("Error: Could not determine binary file name!")
|
||||||
|
|
||||||
# Determine if the build folder exists, and create it if not.
|
# If modules are specified, pre-compile them by calling this script recursively. If using the `std` module, pre-compile it first. If this is a module itself, don't compile any other modules to avoid infinite recursion. (Note: This assumes that modules do not depend on each other.)
|
||||||
if not pathlib.Path(build_folder).exists():
|
recompiled_modules: bool = False
|
||||||
pathlib.Path(build_folder).mkdir()
|
module_paths: dict[str, list[pathlib.Path]] = {name: [(pathlib.Path.cwd() / file).resolve() for file in files] for name, files in modules.items()}
|
||||||
|
module_output_paths: dict[str, pathlib.Path] = {name: build_folder / f"{path[0].stem}_module_{suffix}{module_extension}" for name, path in module_paths.items()}
|
||||||
# If modules are specified, pre-compile them by calling this script recursively, unless the current file is itself a module. As a special case, if the std module is used, we add it even if the current file is a module, in case the module itself wants to import the std module.
|
if use_std_module and "std" in modules:
|
||||||
module_paths: dict[str, list[pathlib.Path]] = {}
|
flags.extend(get_module_flags("std", module_output_paths["std"]))
|
||||||
if not args.as_module:
|
if not args.as_module:
|
||||||
module_paths = {name: [(pathlib.Path.cwd() / file).resolve() for file in files] for name, files in modules.items()}
|
if use_std_module and "std" in modules:
|
||||||
elif use_std_module and "std" in modules:
|
recompiled_modules |= compile_module("std", [(pathlib.Path.cwd() / modules["std"][0]).resolve()], module_output_paths["std"])
|
||||||
module_paths = {"std": [(pathlib.Path.cwd() / modules["std"][0]).resolve()]}
|
|
||||||
if len(modules) > 0 and (args.std in ["c++20", "c++23"]):
|
|
||||||
for name, paths in module_paths.items():
|
|
||||||
module_flags: list[str] = args.flag[:]
|
|
||||||
module_extension: str
|
|
||||||
if compiler == "cl":
|
|
||||||
module_extension = ".ifc"
|
|
||||||
module_flags = ["/interface", "/TP", "/c"]
|
|
||||||
elif compiler == "clang++":
|
|
||||||
module_extension = ".pcm"
|
|
||||||
module_flags = ["--precompile", "-Wno-include-angled-in-module-purview", "-Wno-reserved-module-identifier", "-xc++-module"]
|
|
||||||
else: # compiler == "g++"
|
|
||||||
# Note: Creating an object file can be disabled with `-fmodule-only`, and it doesn't seem like the object file is actually needed, only the `.gcm` file. However, we create the object file anyway so we can check if the module is up to date, since there appears to be no way to control the name of the `.gcm` file.
|
|
||||||
module_extension = ".o"
|
|
||||||
module_flags = ["-fmodules-ts", "-xc++", "-c", f"-fmodule-mapper=|@g++-mapper-server -r{build_folder}"]
|
|
||||||
# Only the first file on the list needs to be compiled; the rest are dependencies that are only used to check if the compiled module is up to date.
|
|
||||||
module_file: pathlib.Path = paths[0]
|
|
||||||
module_output_path: pathlib.Path = build_folder / f"{module_file.stem}_module_{suffix}{module_extension}"
|
|
||||||
if compiler == "cl":
|
|
||||||
flags.extend(["/reference", f"{name}={module_output_path.resolve()}"])
|
|
||||||
if name != "std" or not args.as_module:
|
|
||||||
flags.append(str(build_folder / f"{module_output_path.stem}.obj"))
|
|
||||||
elif compiler == "clang++":
|
|
||||||
flags.append(f"-fmodule-file={name}={module_output_path.resolve()}")
|
|
||||||
else: # compiler == "g++"
|
|
||||||
flags.append("-fmodules-ts")
|
|
||||||
flags.append(f"-fmodule-mapper=|@g++-mapper-server -r{build_folder}")
|
|
||||||
if module_output_path.exists():
|
|
||||||
module_output_mod: float = module_output_path.stat().st_mtime
|
|
||||||
if not any((path.exists() and path.stat().st_mtime > module_output_mod) for path in paths):
|
|
||||||
print_if_verbose(f'Module "{name}" is up to date, skipping compilation.')
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
command: list[str] = [
|
|
||||||
"python" if platform.system() == "Windows" else "python3",
|
|
||||||
str(pathlib.Path(__file__).resolve()),
|
|
||||||
str(module_file),
|
|
||||||
f"-o={module_output_path.resolve()}",
|
|
||||||
f"-a={args.arch}",
|
|
||||||
f"-c={compiler}",
|
|
||||||
f"-s={args.std}",
|
|
||||||
f"-t={args.type}",
|
|
||||||
# Note: Not adding the extra options from the configuration file, since they will be added by the script anyway.
|
|
||||||
*[f"-d={define}" for define in args.define],
|
|
||||||
*[f"-i={include}" for include in args.include],
|
|
||||||
*[f"-f={flag}" for flag in (args.flag + module_flags)],
|
|
||||||
# If compiling the `std` module itself, we need to pass `-u disable` to avoid infinite recursion. Otherwise, we pass along the specified module path if it exists.
|
|
||||||
*(["-u=disable"] if name == "std" else [f"-u={std_module}"] if std_module is not None else []),
|
|
||||||
"-l",
|
|
||||||
*(["-v"] if args.verbose else []),
|
|
||||||
]
|
|
||||||
print_if_verbose(separator)
|
|
||||||
print_if_verbose(f'Compiling module "{name}" with command: {subprocess.list2cmdline(command)}')
|
|
||||||
compile_result: subprocess.CompletedProcess[str] = subprocess.run(
|
|
||||||
args=command,
|
|
||||||
check=False,
|
|
||||||
text=True,
|
|
||||||
)
|
|
||||||
if compile_result.returncode != 0:
|
|
||||||
sys.exit(f"Module compilation failed with return code: {compile_result.returncode}.")
|
|
||||||
except Exception as exc:
|
|
||||||
sys.exit(f"Could not compile module due to exception: {exc}.")
|
|
||||||
print_if_verbose("Compiling program...")
|
|
||||||
|
|
||||||
# Collect the full paths to the include folders, relative to the current working directory.
|
|
||||||
include_paths: list[pathlib.Path] = [(pathlib.Path.cwd() / folder).resolve() for folder in includes]
|
|
||||||
|
|
||||||
# On macOS, make sure we are using Homebrew Clang, if available, instead of Apple Clang, which does not support C++20 modules.
|
|
||||||
compiler_path: str | None
|
|
||||||
if compiler == "clang++" and platform.system() == "Darwin":
|
|
||||||
compiler_path = "/usr/local/opt/llvm/bin/clang++"
|
|
||||||
if not pathlib.Path(compiler_path).exists():
|
|
||||||
compiler_path = shutil.which(compiler)
|
|
||||||
else:
|
|
||||||
compiler_path = shutil.which(compiler)
|
|
||||||
|
|
||||||
# Determine the command to execute based on the chosen compiler and parameters.
|
|
||||||
command: list[str]
|
|
||||||
if compiler == "clang++":
|
|
||||||
command = [
|
|
||||||
compiler_path if compiler_path is not None else compiler,
|
|
||||||
*flags,
|
|
||||||
*[str(path.resolve()) for path in source_paths],
|
|
||||||
f"-std={args.std}",
|
|
||||||
"-g3" if args.type == "debug" else "-O3",
|
|
||||||
"-o",
|
|
||||||
str(executable_path),
|
|
||||||
*([] if platform.system() == "Windows" else ["-pthread"]),
|
|
||||||
*[item for include in [["-I", str(path.resolve())] for path in include_paths] for item in include],
|
|
||||||
*([f"-D{define}" for define in defines]),
|
|
||||||
]
|
|
||||||
elif compiler == "g++":
|
|
||||||
if len(modules) > 0 and (args.std in ["c++20", "c++23"]):
|
if len(modules) > 0 and (args.std in ["c++20", "c++23"]):
|
||||||
print_if_verbose(
|
for n, p in module_paths.items():
|
||||||
"NOTE: GCC v14.2.0 appears to have an internal compiler error when compiling programs containing modules with any optimization flags other than -Og enabled. Until this is fixed, if you wish to use compiler optimizations, please either include the library as a header file or use a different compiler.",
|
if n == "std":
|
||||||
)
|
continue
|
||||||
command = [
|
flags.extend(get_module_flags(n, module_output_paths[n]))
|
||||||
compiler_path if compiler_path is not None else compiler,
|
recompiled_modules |= compile_module(n, p, module_output_paths[n])
|
||||||
*flags,
|
print_if_verbose("Compiling program...", ANSI_INFO)
|
||||||
*[str(path.resolve()) for path in source_paths],
|
|
||||||
f"-std={args.std}",
|
|
||||||
"-ggdb3" if args.type == "debug" else "-O3" if not (len(modules) > 0 and (args.std in ["c++20", "c++23"])) else "-Og",
|
|
||||||
"-o",
|
|
||||||
str(executable_path),
|
|
||||||
*([] if platform.system() == "Windows" else ["-pthread"]),
|
|
||||||
*[item for include in [["-I", str(path.resolve())] for path in include_paths] for item in include],
|
|
||||||
*([f"-D{define}" for define in defines]),
|
|
||||||
]
|
|
||||||
else: # compiler == "cl"
|
|
||||||
command = [
|
|
||||||
compiler_path if compiler_path is not None else compiler,
|
|
||||||
*flags,
|
|
||||||
*[str(path.resolve()) for path in source_paths],
|
|
||||||
f"/std:{"c++latest" if args.std == "c++23" else args.std}",
|
|
||||||
*(["/Zi", f"/Fd:{executable_path.with_suffix(".pdb")}"] if args.type == "debug" else ["/O2"]),
|
|
||||||
*([f"/Fe:{executable_path}"] if not args.as_module else ["/ifcOutput", str(executable_path)]),
|
|
||||||
f"/Fo:{executable_path.with_suffix(".obj")}",
|
|
||||||
*[item for include in [["/I", str(path.resolve())] for path in include_paths] for item in include],
|
|
||||||
"/permissive-",
|
|
||||||
"/EHsc",
|
|
||||||
"/nologo",
|
|
||||||
"/Zc:__cplusplus",
|
|
||||||
*([f"/D{define}" for define in defines]),
|
|
||||||
]
|
|
||||||
|
|
||||||
# For MSVC we also need to invoke the Visual Studio Developer PowerShell script.
|
# If the output binary already exists, check if we need to recompile based on whether any of the source files or their dependencies have changed. If we recompiled any modules, we need to recompile anyway, so we don't need to check the dependencies. The `force` flag overrides this check.
|
||||||
if compiler == "cl":
|
need_recompile: bool = True
|
||||||
command = ["pwsh.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", f"& '{vs_pwsh_path}' -Arch {args.arch} -HostArch {args.arch} | Out-Null; {subprocess.list2cmdline(command)}"]
|
deps_paths: list[pathlib.Path] = [(pathlib.Path.cwd() / file).resolve() for file in deps]
|
||||||
|
if not args.force and not recompiled_modules and binary_path.exists():
|
||||||
|
binary_mod: float = binary_path.stat().st_mtime
|
||||||
|
if not any((path.exists() and path.stat().st_mtime > binary_mod) for path in (source_paths + deps_paths)):
|
||||||
|
print_if_verbose("Binary is up to date, skipping compilation.", ANSI_INFO)
|
||||||
|
need_recompile = False
|
||||||
|
|
||||||
print_if_verbose(separator)
|
if need_recompile:
|
||||||
print_if_verbose(f"Compiler: {compiler}")
|
include_paths: list[pathlib.Path] = [(pathlib.Path.cwd() / folder).resolve() for folder in includes]
|
||||||
print_if_verbose(f"C++ Standard: {args.std.upper()}")
|
# On macOS, make sure we are using Homebrew Clang, if available, instead of Apple Clang, which does not support C++20 modules.
|
||||||
print_if_verbose(f"Type: {args.type.title()}")
|
compiler_path: str | None
|
||||||
print_if_verbose(f"Source file(s): [{", ".join([str(path) for path in source_paths])}]")
|
if compiler == "clang++" and platform.system() == "Darwin":
|
||||||
print_if_verbose(f"Defines: [{", ".join(defines)}]")
|
compiler_path = "/usr/local/opt/llvm/bin/clang++"
|
||||||
print_if_verbose(f"Flags: [{", ".join(flags)}]")
|
if not pathlib.Path(compiler_path).exists():
|
||||||
print_if_verbose(f"Includes: [{(", ".join([str(path) for path in include_paths]))}]")
|
compiler_path = shutil.which(compiler)
|
||||||
if args.std in ["c++20", "c++23"]:
|
|
||||||
print_if_verbose(f"Modules: [{", ".join(f"{name}={path[0]}" for name, path in module_paths.items()) if not args.as_module else ""}]")
|
|
||||||
else:
|
|
||||||
print_if_verbose("Modules: <Unused in C++17 mode>")
|
|
||||||
print_if_verbose(f"Build folder: {build_folder}")
|
|
||||||
print_if_verbose(f"Binary file: {executable_path.name}")
|
|
||||||
print_if_verbose(f"Command: {subprocess.list2cmdline(command)}")
|
|
||||||
|
|
||||||
# Perform the actual compilation.
|
|
||||||
print_if_verbose(separator)
|
|
||||||
print_if_verbose("Compiling...")
|
|
||||||
success = False
|
|
||||||
try:
|
|
||||||
compile_start: float = time.perf_counter()
|
|
||||||
compile_result: subprocess.CompletedProcess[str] = subprocess.run(
|
|
||||||
args=command,
|
|
||||||
check=False,
|
|
||||||
text=True,
|
|
||||||
)
|
|
||||||
if compile_result.returncode == 0:
|
|
||||||
print_if_verbose(f"Compilation completed successfully in {time.perf_counter() - compile_start:.2f} seconds.")
|
|
||||||
success = True
|
|
||||||
else:
|
else:
|
||||||
sys.exit(f"Compilation failed with return code: {compile_result.returncode}.")
|
compiler_path = shutil.which(compiler)
|
||||||
except Exception as exc:
|
|
||||||
sys.exit(f"Could not compile due to exception: {exc}.")
|
|
||||||
|
|
||||||
# If there were compilation errors, delete the executable file if it exists, so the IDE won't mistakenly run the old version anyway.
|
# Determine the command to execute based on the chosen compiler and parameters.
|
||||||
if not success and executable_path.exists():
|
command: list[str]
|
||||||
executable_path.unlink()
|
if compiler == "clang++":
|
||||||
|
command = [
|
||||||
|
compiler_path if compiler_path is not None else compiler,
|
||||||
|
*flags,
|
||||||
|
*[str(path.resolve()) for path in source_paths],
|
||||||
|
f"-std={args.std}",
|
||||||
|
"-g3" if args.type == "debug" else "-O3",
|
||||||
|
"-o",
|
||||||
|
str(binary_path),
|
||||||
|
*[item for include in [["-I", str(path.resolve())] for path in include_paths] for item in include],
|
||||||
|
*([f"-D{define}" for define in defines]),
|
||||||
|
]
|
||||||
|
elif compiler == "g++":
|
||||||
|
command = [
|
||||||
|
compiler_path if compiler_path is not None else compiler,
|
||||||
|
*flags,
|
||||||
|
# In the special case of GCC and the `std` module, `bits/std.cc` must be entered without the full path.
|
||||||
|
*[(str(path.resolve()) if path != pathlib.Path(gcc_std_path) else gcc_std_path) for path in source_paths],
|
||||||
|
f"-std={args.std}",
|
||||||
|
"-ggdb3" if args.type == "debug" else "-O3",
|
||||||
|
"-o",
|
||||||
|
str(binary_path),
|
||||||
|
*[item for include in [["-I", str(path.resolve())] for path in include_paths] for item in include],
|
||||||
|
*([f"-D{define}" for define in defines]),
|
||||||
|
]
|
||||||
|
else: # compiler == "cl"
|
||||||
|
command = [
|
||||||
|
compiler_path if compiler_path is not None else compiler,
|
||||||
|
*flags,
|
||||||
|
*[str(path.resolve()) for path in source_paths],
|
||||||
|
f"/std:{'c++latest' if args.std == 'c++23' else args.std}",
|
||||||
|
*(["/Zi", f"/Fd:{binary_path.with_suffix('.pdb')}"] if args.type == "debug" else ["/O2"]),
|
||||||
|
*([f"/Fe:{binary_path}"] if not args.as_module else ["/ifcOutput", str(binary_path)]),
|
||||||
|
# If compiling multiple source files, we cannot specify the names of each object file, only the output folder.
|
||||||
|
f"/Fo:{binary_path.with_suffix('.obj')}" if len(source_paths) == 1 else f"/Fo:{build_folder}\\",
|
||||||
|
*[item for include in [["/I", str(path.resolve())] for path in include_paths] for item in include],
|
||||||
|
"/permissive-",
|
||||||
|
"/nologo",
|
||||||
|
"/Zc:__cplusplus",
|
||||||
|
*([f"/D{define}" for define in defines]),
|
||||||
|
]
|
||||||
|
|
||||||
|
# For MSVC we also need to invoke the Visual Studio Developer PowerShell script.
|
||||||
|
if compiler == "cl" and vs_path is not None:
|
||||||
|
vs_pwsh_path: pathlib.Path = vs_path / "Common7" / "Tools" / "Launch-VsDevShell.ps1"
|
||||||
|
command = ["pwsh.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", f"& '{vs_pwsh_path}' -Arch {args.arch} -HostArch {args.arch} | Out-Null; {subprocess.list2cmdline(command)}"]
|
||||||
|
|
||||||
|
print_separator()
|
||||||
|
max_length = 16
|
||||||
|
print_key_values("Compiler", [compiler], max_length)
|
||||||
|
print_key_values("C++ Standard", [args.std.upper()], max_length)
|
||||||
|
print_key_values("Type", [args.type.title()], max_length)
|
||||||
|
print_key_values("Source file(s)", [str(relative_or_full_path(path)) for path in source_paths], max_length)
|
||||||
|
print_key_values("Defines", defines, max_length)
|
||||||
|
print_key_values("Dependencies", [str(relative_or_full_path(path)) for path in deps_paths], max_length)
|
||||||
|
print_key_values("Flags", flags, max_length)
|
||||||
|
print_key_values("Includes", ([str(relative_or_full_path(path)) for path in include_paths]), max_length)
|
||||||
|
if args.std in ["c++20", "c++23"]:
|
||||||
|
print_key_values("Modules", [f"{name}={relative_or_full_path(path[0])}" for name, path in module_paths.items()] if not args.as_module else ["<None>"], max_length)
|
||||||
|
else:
|
||||||
|
print_key_values("Modules", ["<Unused in C++17 mode>"], max_length)
|
||||||
|
print_key_values("Build folder", [str(relative_or_full_path(build_folder))], max_length)
|
||||||
|
print_key_values("Binary file", [str(relative_or_full_path(binary_path))], max_length)
|
||||||
|
print_key_values("Command", [subprocess.list2cmdline(command)], max_length)
|
||||||
|
print_separator()
|
||||||
|
|
||||||
|
# Perform the actual compilation.
|
||||||
|
print_if_verbose("Compiling...", ANSI_INFO)
|
||||||
|
try:
|
||||||
|
_ = sys.stdout.flush()
|
||||||
|
compile_start: float = time.perf_counter()
|
||||||
|
compile_result = subprocess.run(
|
||||||
|
args=command,
|
||||||
|
check=False,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
if compile_result.returncode == 0:
|
||||||
|
print_if_verbose(f"Compilation completed successfully in {time.perf_counter() - compile_start:.2f} seconds.", ANSI_SUCCESS)
|
||||||
|
else:
|
||||||
|
print_error_and_exit(f"Compilation failed with return code: {compile_result.returncode}.")
|
||||||
|
except Exception as exc:
|
||||||
|
print_error_and_exit(f"Could not compile due to exception: {exc}.")
|
||||||
|
|
||||||
if args.run:
|
if args.run:
|
||||||
# We run the program in the build folder.
|
# We run the program in the build folder.
|
||||||
os.chdir(build_folder)
|
os.chdir(build_folder)
|
||||||
print_if_verbose(f"Running program{f" with arguments {" ".join(pass_args)}" if len(pass_args) > 0 else ""}...")
|
print_if_verbose(f"Running program{f' with arguments {" ".join(pass_args)}' if len(pass_args) > 0 else ''}...", ANSI_INFO)
|
||||||
print_if_verbose(separator)
|
print_separator()
|
||||||
try:
|
try:
|
||||||
|
_ = sys.stdout.flush()
|
||||||
run_start: float = time.perf_counter()
|
run_start: float = time.perf_counter()
|
||||||
run_result: subprocess.CompletedProcess[str] = subprocess.run(
|
run_result: subprocess.CompletedProcess[str] = subprocess.run(
|
||||||
args=[executable_path, *pass_args],
|
args=[binary_path, *pass_args],
|
||||||
check=False,
|
check=False,
|
||||||
text=True,
|
text=True,
|
||||||
)
|
)
|
||||||
print_if_verbose(separator)
|
print_separator()
|
||||||
if run_result.returncode == 0:
|
if run_result.returncode == 0:
|
||||||
print_if_verbose(f"Program executed successfully in {time.perf_counter() - run_start:.2f} seconds.")
|
print_if_verbose(f"Program executed successfully in {time.perf_counter() - run_start:.2f} seconds.", ANSI_SUCCESS)
|
||||||
else:
|
else:
|
||||||
sys.exit(f"Program failed with return code: {run_result.returncode}.")
|
print_error_and_exit(f"Program failed with return code: {run_result.returncode}.")
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print_if_verbose(separator)
|
print_separator()
|
||||||
sys.exit(f"Could not run program due to exception: {exc}.")
|
print_error_and_exit(f"Could not run program due to exception: {exc}.")
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
"""
|
|
||||||
██████ ███████ ████████ ██ ██ ██████ ███████ █████ ██████ ██████ ██████ ██████ ██
|
|
||||||
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
||||||
██████ ███████ ██ ███████ ██████ █████ ███████ ██ ██ ██████ ██ ██ ██ ██ ██
|
|
||||||
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
||||||
██████ ███████ ██ ██ ██ ██ ██ ███████ ██ ██ ██████ ███████ ██ ██████ ██████ ███████
|
|
||||||
|
|
||||||
`BS::thread_pool`: a fast, lightweight, modern, and easy-to-use C++17/C++20/C++23 thread pool library
|
|
||||||
v5.0.0 (2024-12-19)
|
|
||||||
By Barak Shoshany <baraksh@gmail.com> <https://baraksh.com/>
|
|
||||||
Copyright (c) 2024 Barak Shoshany. Licensed under the MIT license. If you found this project useful, please consider starring it on GitHub! If you use this library in software of any kind, please provide a link to the GitHub repository https://github.com/bshoshany/thread-pool in the source code and documentation. If you use this library in published research, please cite it as follows: Barak Shoshany, "A C++17 Thread Pool for High-Performance Scientific Computing", doi:10.1016/j.softx.2024.101687, SoftwareX 26 (2024) 101687, arXiv:2105.00613
|
|
||||||
|
|
||||||
This Python script is used in the library's development environment to compile and run the test program using all possible combinations of compilers and C++ standards available in the system, in order to test compatibility.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import pathlib
|
|
||||||
import platform
|
|
||||||
import shutil
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
|
||||||
_ = parser.add_argument("--compile-only", action="store_true", help="only check that the program compiles successfully with all compilers, without running it")
|
|
||||||
parsed_args: argparse.Namespace = parser.parse_args()
|
|
||||||
|
|
||||||
|
|
||||||
def print_message(message: str) -> None:
|
|
||||||
"""Print a message with indicator characters to differentiate it from messages from the compile script."""
|
|
||||||
print(f"\n >>>>> {message} <<<<<\n")
|
|
||||||
|
|
||||||
|
|
||||||
# Determine which compilers are available.
|
|
||||||
vs_pwsh_path: str = r"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1"
|
|
||||||
compilers: list[str] = []
|
|
||||||
if pathlib.Path(vs_pwsh_path).exists():
|
|
||||||
compilers.append("cl")
|
|
||||||
if shutil.which("clang++") is not None:
|
|
||||||
compilers.append("clang++")
|
|
||||||
# On macOS, g++ is by default just an alias for clang++, so we skip it.
|
|
||||||
if shutil.which("g++") is not None and platform.system() != "Darwin":
|
|
||||||
compilers.append("g++")
|
|
||||||
|
|
||||||
# Compile using all available compilers using all relevant C++ standards.
|
|
||||||
standards: list[str] = ["c++17", "c++20", "c++23"]
|
|
||||||
workspace_path: pathlib.Path = pathlib.Path(__file__).parent.parent.resolve()
|
|
||||||
source_path: pathlib.Path = workspace_path / "tests" / "BS_thread_pool_test.cpp"
|
|
||||||
script_path: pathlib.Path = workspace_path / "scripts" / "compile_cpp.py"
|
|
||||||
try:
|
|
||||||
compile_start: float = time.perf_counter()
|
|
||||||
for compiler in compilers:
|
|
||||||
for std in standards:
|
|
||||||
print_message(f"Compiling with {compiler} using {std.upper()} standard...")
|
|
||||||
warnings_as_errors: list[str] = ["-f/WX"] if compiler == "cl" else ["-f-Werror"]
|
|
||||||
command: list[str] = [
|
|
||||||
"python" if platform.system() == "Windows" else "python3",
|
|
||||||
str(script_path.resolve()),
|
|
||||||
str(source_path.resolve()),
|
|
||||||
"-c",
|
|
||||||
compiler,
|
|
||||||
"-s",
|
|
||||||
std,
|
|
||||||
"-t",
|
|
||||||
"release",
|
|
||||||
*warnings_as_errors,
|
|
||||||
*(["-r"] if not parsed_args.compile_only else []),
|
|
||||||
"-p",
|
|
||||||
"stdout",
|
|
||||||
"-p",
|
|
||||||
"log",
|
|
||||||
"-p",
|
|
||||||
"tests",
|
|
||||||
"-v",
|
|
||||||
]
|
|
||||||
compile_result: subprocess.CompletedProcess[str] = subprocess.run(
|
|
||||||
args=command,
|
|
||||||
check=False,
|
|
||||||
text=True,
|
|
||||||
)
|
|
||||||
if compile_result.returncode != 0:
|
|
||||||
print_message("Compilation failed, aborting script!")
|
|
||||||
sys.exit(compile_result.returncode)
|
|
||||||
except Exception as exc:
|
|
||||||
print_message(f"Could not compile due to exception: {exc}.")
|
|
||||||
sys.exit(1)
|
|
||||||
print_message(f"All tests completed successfully in {time.perf_counter() - compile_start:.2f} seconds.")
|
|
||||||
+837
-351
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user