Getting Started

Build the runtime, select a narrow component and run a small native C++ program.

BeginnerCMakeVerified example

Requirements

  • CMake 3.20 or newer
  • A compiler with the required C++23 features
  • Git; initialize the GoogleTest submodule only if building Sharp Runtime’s tests
  • ZLIB when selecting IO.Compression or All

Create the consumer

Place the Sharp Runtime checkout at sharp-runtime/ beside these two files. The component list must be set before add_subdirectory.

cmake_minimum_required(VERSION 3.20)
project(hello_sharp_runtime LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(SHARP_RUNTIME_COMPONENTS Console)
set(SHARP_RUNTIME_BUILD_TESTS OFF CACHE BOOL "" FORCE)
add_subdirectory(sharp-runtime)

add_executable(hello main.cpp)
target_link_libraries(hello PRIVATE SharpRuntime::Console)
#include <System/Console.hpp>

int main()
{
    System::Console::WriteLine("Hello from native C++23.");
    return 0;
}

Configure and run

cmake -S . -B build
cmake --build build --parallel 2
./build/hello

Select more components

List direct needs using semicolons. Sharp Runtime resolves their transitive closure, so an application does not repeat dependencies.

set(SHARP_RUNTIME_COMPONENTS
    Text.Json
    IO.Hashing
)

target_link_libraries(my_app PRIVATE
    SharpRuntime::Text.Json
    SharpRuntime::IO.Hashing
)
Embed explicitly

A standalone Sharp Runtime build defaults to All. An embedding application should always set SHARP_RUNTIME_COMPONENTS explicitly and normally disable the runtime’s own tests.

Build the runtime tests

cmake -S sharp-runtime -B runtime-build \
  -DSHARP_RUNTIME_COMPONENTS=All \
  -DSHARP_RUNTIME_BUILD_TESTS=ON
cmake --build runtime-build --target SharpRuntimeTests --parallel 2
sharp-runtime/scripts/run_component_tests.sh runtime-build

Next steps