Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(OPENTS_VERSION_PRERELEASE "")
option(OPENTS_OFFICIAL_BUILD "Build as an official release of the declared version" OFF)

option(OPENTS_EXPERIMENTAL_CLANG_CL "Build with clang-cl using the MSVC ABI" OFF)
option(OPENTS_EXPERIMENTAL_NATIVE "Configure a native build for the host platform" OFF)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

project() enables ASM_MASM before this option exists, CMake searches for ml/ml64 and a linux or mac host then fails before reaching the opt-in. Move MASM out of project().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. project() dropped ASM_MASM:

869f7d9


if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
Expand All @@ -24,14 +25,31 @@ elseif(MSVC)
if(MSVC_VERSION LESS 1930)
message(FATAL_ERROR "OpenTS requires MSVC 19.30 or newer.")
endif()
elseif(OPENTS_EXPERIMENTAL_NATIVE)
message(STATUS "OpenTS: configuring an unsupported native build for the host platform.")

# The tree declares imports and exports with __declspec throughout, which clang only
# accepts with the Microsoft extensions enabled.
add_compile_options(-fms-extensions)

# Saved games serialize pointer fields at their native width.
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 4)
message(WARNING
"OpenTS: this native build has ${CMAKE_SIZEOF_VOID_P}-byte pointers. Saved games "
"it writes are not interchangeable with a supported 32-bit build's.")
endif()
else()
message(FATAL_ERROR
"OpenTS requires the Visual Studio 2022 MSVC toolchain. "
"For the unsupported clang-cl experiment, configure with "
"-DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/clang-cl-msvc.cmake.")
"-DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/clang-cl-msvc.cmake. "
"For the unsupported native build, configure with "
"-DOPENTS_EXPERIMENTAL_NATIVE=ON.")
endif()

enable_language(RC)
if(WIN32)
enable_language(RC)
endif()

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
18 changes: 10 additions & 8 deletions code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE STRING "" FORCE)

# OpenTS currently supports 32-bit (x86) builds only.
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 4)
if(WIN32 AND NOT CMAKE_SIZEOF_VOID_P EQUAL 4)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This permits 64bit native builds, cool, but SaveStreamClass::Serialize(T *&) writes sizeof(pointer) bytes. A 64-bit binary would then use a different save representation under the same packed project version. I guess try and contain native builds from save/network runtime use, retain the 32-bit constraint.

@mischa85 mischa85 Sep 8, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's broader than SaveStreamClass::Serialize(T *&) as every object writes its own address as its swizzle identity here, so a 64-bit save differs in layout from the first object header, not in a few fields.

The in-memory side is fine, it's uintptr_t everywhere. What's wrong is the file taking its identity from an address at all. A width-independent key assigned at save time would end this whole class of problem, and #140 is the natural place for it.

message(FATAL_ERROR "OpenTS must be built as 32-bit x86. Reconfigure with -A Win32.")
endif()

Expand Down Expand Up @@ -156,7 +156,7 @@ set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/bgfxbackend.cpp" PROPER
"${BGFX_ROOT}/include;${CMAKE_SOURCE_DIR}/thirdparty/bgfx.cmake/bx/include;${BGFX_ROOT}/examples/common/imgui"
COMPILE_DEFINITIONS
"BX_CONFIG_DEBUG=$<IF:$<CONFIG:Debug>,1,$<BOOL:${BX_CONFIG_DEBUG}>>"
COMPILE_OPTIONS "/Zc:preprocessor"
COMPILE_OPTIONS "$<$<BOOL:${MSVC}>:/Zc:preprocessor>"
)

# bx rewrites __stdcall while its headers are being parsed by clang-cl. Force the
Expand Down Expand Up @@ -318,12 +318,14 @@ add_custom_command(TARGET OpenTS POST_BUILD
"${TS_RUN_DIR}"
)

# Copy the linker-generated .pdb alongside the exe
add_custom_command(TARGET OpenTS POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_PDB_FILE:OpenTS>"
"${TS_RUN_DIR}"
)
# Copy the linker-generated .pdb alongside the exe. Only the MSVC linker writes one.
if(MSVC)
add_custom_command(TARGET OpenTS POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_PDB_FILE:OpenTS>"
"${TS_RUN_DIR}"
)
endif()

# Copy the linker-generated .map (sits next to the exe, no GenEx for it)
add_custom_command(TARGET OpenTS POST_BUILD
Expand Down
23 changes: 23 additions & 0 deletions docs/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,29 @@ The toolchain requires `clang-cl`, `lld-link`, `llvm-lib`, `llvm-mt`, and
`llvm-rc` on `PATH`. It exports `compile_commands.json`; one configuration in
`.vscode/c_cpp_properties.clang.example.json` reads that file for IntelliSense.

## Experimental native build

An unsupported native build for the host platform is available for portability
work. It configures; the engine target does not compile yet. It does not expand
the supported build matrix or establish runtime behavior.

```bash
cmake -S . -B build/native -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DOPENTS_EXPERIMENTAL_NATIVE=ON
```

Building the generated tree compiles the vendored dependencies and stops on
every engine source, because `code/CMakeLists.txt` passes the MSVC flag set
unconditionally. `/arch:SSE2` and `/fp:precise` carry the float semantics the
simulation depends on, so a native equivalent is a decision to make rather than
a translation. Windows headers and import libraries are named unconditionally
as well.

A native build takes the host's pointer width, and saved games serialize pointer
fields at that width, so a 64-bit build's saves are not interchangeable with a
supported build's.

## Build from Visual Studio Code

With the recommended extensions installed, the repository provides:
Expand Down