SC::Tools are self contained single C++ source files that are (automatically) compiled on the fly and linked to Sane C++ to be immediately executed.
They leverage the growing shell, system and network programming capabilities of Sane C++ Libraries, by just including the SC.cpp unity build file, that has no third party dependencies (see Building (Contributor)).
Another way to look at them is just as small C++ scripts for which you don't need to setup or maintain a build system, as long as you only use Sane C++ Libraries.
SC::Tools and not SC::Scripts because they're still just small programs. Some relevant blog posts are:
SC::Tools has been created for the following reasons:
Tools/SC-package.cpp uses SC::Process library to download some third party binaryTools/SC-package.cpp uses SC::Hashing library to check downloaded package hashesTools/SC-format.cpp uses SC::FileSystemIterator library to find all files to format in the repoAll built-in tools are invoked with the SC.sh or SC.bat bootstrap script that is located in the root of the repo.
Such script must be called with the name of the tool and some parameters.
For Example, invoking the Tools\SC-build.cpp tool with configure action:
or (on Windows)
SC::Tools are just regular programs being compiled on the fly when needed, so they require a working host compiler to be available in system path. This limitation could be removed if needed, as described in the Roadmap section. Tools can be automatically compiled and run by just passing its full path to the SC bootstrap.
Given the following custom tool at myToolDirectory/TestScript.cpp
This is how to invoke the tool with action and some parameters
or (on Windows):
Possible output (Posix):
This is the list of tools that currently exist in the Sane C++ repository.
SC-build configures generated projects and can also build Sane C++ repository targets directly through the standalone native backend in SC::Build.
configure: Generates repository projects into _Build/_Projects/<Generator>/<Workspace>compile: Builds one project or an entire workspace through the selected backendrun: Builds a single executable target if needed and then runs itcoverage: Builds clang coverage output into _Build/_Coveragedocumentation: Builds the documentation into _Build/_DocumentationSC-build command shape:
Generator keywords are default, native, make, xcode, vs2022, and vs2019.
Current defaults:
default resolves to vs2022default resolves to makeconfigure stepConfigure project, generating them:
Possible Output:
Build all projects
Build through the native backend
Run a generated-backend executable and pass extra test arguments after --
Open generated projects:
_Build/_Projects/XCode/SCWorkspace/SCWorkspace.xcworkspace_Build/_Projects/VisualStudio2022/SCWorkspace/SCWorkspace.sln_Build/_Projects/VisualStudio2019/SCWorkspace/SCWorkspace.sln_Build/_Projects/Make/SCWorkspace/apple_Build/_Projects/Make/SCWorkspace/linuxPossible Output:
SC-package downloads third party tools needed for Sane C++ development (example: clang-format).
Proper OS / Architecture combination is selected (Windows/Linux/Mac and Intel/ARM) and all downloaded files (packages) are hash checked for correctness.
Packages are placed and extracted in _Build/_Packages while downloaded archives are reused from _Build/_PackagesCache.
install: Downloads required tools (LLVM archives / documentation tools)These are the packages that are currently downloaded and extracted / symlinked by SC-package.cpp:
LLVM 20.1.8: Downloads clang-format from the official LLVM github repository using SHA256 pinned archivesdoxygen: Doxygen documentation generatordoxygen-awesome-css: Doxygen awesome css (Doxygen theme)clang-format install is available on macOS ARM64, Linux ARM64/x64 and Windows ARM64/x64. llvm@20 manually (for example through Homebrew) because recent official LLVM releases no longer provide Intel macOS archives.SC-format tool formats or checks formatting for all files in Sane C++ repository
execute: Formats all source files in the repository in-placecheck: Does a dry-run format of all source files. Returns error on unformatted files (used by the CI)Format all source files in the repository
Check if all source files in the repository are properly formatted
The bootstrap batch (SC.bat) / bash (SC.sh) shell scripts are doing the following:
.cpp files are compiled (only if they're out of date) by a MakefileTools/Tools.cpp fileSC.cpp unity build file, defining main(argc, argv)$TOOL.cpp file$TOOL name is the main $ACTION by convention$ACTION and all $PARAM_X arguments passed to the bootstrap shell scripts are forwarded to the toolExample:
SC.sh $TOOL $ACTION $PARAM_1 $PARAM_2 ... $PARAM_N
Tools.cpp is shared between all compiled tools by the Makefile inside the _Build/_Tools/_Intermediates directory. Tools.cpp.SC::Tools define an handy way of invoking an on the fly compiled program that has Sane C++ Libraries. The bootstrap process bringing from the command line to final execution is the following:
./SC.sh build compile SCTest DebugSC.sh is the ${TOOL_NAME} (in this case build)SC.sh checks if Tools/ToolsBootstrap executable exists and is up to date with Tools/ToolsBootstrap.cTools/ToolsBootstrap.c to create the bootstrap executableSC.sh invokes Tools/ToolsBootstrap with the library directory, tool source directory, build directory, tool name, and any additional argumentsSC.bat setting up the MSVC environment and compiling Tools/ToolsBootstrap.exe if neededToolsBootstrap receives 3 predefined arguments: a. The directory of SC Libraries ${LIBRARY_DIR} b. The directory containing Tools ${TOOL_SOURCE_DIR} c. The build products directory ${BUILD_DIR} containing intermediates and final productsToolsBootstrap checks if the selected tool executable exists and is up to dateToolsBootstrap compiles Tools/Tools.cpp and the selected tool source (for example Tools/SC-build.cpp)ToolsBootstrap invokes the compiled tool with the original action and parametersSC-build tool then configures projects, compiles, runs, or performs the selected actionTools\Build\$(PLATFORM) makefiles.[*] Running the Sane C++ Tools scripts on a machine without a pre-installed compiler could be implemented by shipping a pre-compiled SC-package.cpp (that is already capable of downloading clang on all platforms) or by adding to the bootstrap script ability to download a suitable compiler (and sysroot).