mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 19:47:46 -07:00
[Protocol] Single-source-of-truth protocol version + publish @cockatrice/protocol
The protocol version is now declared once in libcockatrice_protocol/protocol_version.json. CMake reads it at configure time and emits a generated protocol_version.h exposing COCKATRICE_PROTOCOL_VERSION; remote_client.cpp and serversocketinterface.cpp both pick it up via the existing libcockatrice_protocol link. The same JSON file is bundled into a new @cockatrice/protocol npm package (scripts/package-protocol.mjs + .github/workflows/protocol-publish.yml) so TypeScript consumers (Sockatrice/webclient) can derive PROTOCOL_VERSION from the identical source instead of hand-typing the literal. The workflow dry-runs npm pack on PRs and publishes to GitHub Packages on stable releases only.
This commit is contained in:
parent
98c00c55ed
commit
cc4a53b850
7 changed files with 214 additions and 2 deletions
|
|
@ -1,5 +1,23 @@
|
|||
# Top-level wrapper for the protobuf library
|
||||
|
||||
# Single source of truth for the network protocol version. The same JSON file is
|
||||
# shipped in the @cockatrice/protocol npm package so TypeScript consumers read
|
||||
# the identical value at runtime. Regex-extracted (instead of string(JSON ...))
|
||||
# so we keep the project's CMake 3.10 floor.
|
||||
set(PROTOCOL_VERSION_JSON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/protocol_version.json")
|
||||
file(READ "${PROTOCOL_VERSION_JSON_PATH}" PROTOCOL_VERSION_JSON)
|
||||
string(REGEX MATCH "\"protocolVersion\"[ \t\r\n]*:[ \t\r\n]*([0-9]+)" _ "${PROTOCOL_VERSION_JSON}")
|
||||
if(NOT CMAKE_MATCH_1)
|
||||
message(FATAL_ERROR "Failed to extract protocolVersion from ${PROTOCOL_VERSION_JSON_PATH}")
|
||||
endif()
|
||||
set(COCKATRICE_PROTOCOL_VERSION "${CMAKE_MATCH_1}")
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${PROTOCOL_VERSION_JSON_PATH}")
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/protocol_version.h.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/libcockatrice/protocol/protocol_version.h"
|
||||
@ONLY
|
||||
)
|
||||
|
||||
add_subdirectory(libcockatrice/protocol/pb)
|
||||
|
||||
add_library(libcockatrice_protocol STATIC)
|
||||
|
|
|
|||
3
libcockatrice_protocol/protocol_version.h.in
Normal file
3
libcockatrice_protocol/protocol_version.h.in
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
// Generated by configure_file() from protocol_version.json. Do not edit.
|
||||
#define COCKATRICE_PROTOCOL_VERSION @COCKATRICE_PROTOCOL_VERSION@
|
||||
3
libcockatrice_protocol/protocol_version.json
Normal file
3
libcockatrice_protocol/protocol_version.json
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"protocolVersion": 14
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue