Skip to content

Commit eeeb66d

Browse files
committed
embed the tokens XML file directly at build time, not run time.
Update CI to have newer compilers.
1 parent 90b5b62 commit eeeb66d

13 files changed

Lines changed: 125 additions & 105 deletions

File tree

.github/workflows/build.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,22 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
os: [ubuntu-22.04,ubuntu-latest,macOS-15-intel,macOS-latest]
15+
os: [ubuntu-24.04,macos-15-intel,macos-26-intel,macos-26]
1616
steps:
17-
- uses: actions/checkout@v5
18-
- run: make -j4
17+
- uses: actions/checkout@v6
18+
19+
- name: Install LLVM 19
20+
if: startsWith(matrix.os, 'ubuntu')
21+
run: sudo apt-get update && sudo apt-get install -y clang-19 lld-19
22+
23+
- name: Build
24+
if: startsWith(matrix.os, 'ubuntu')
25+
run: make -j4 CC=clang-19 CXX=clang++-19 LFLAGS=-fuse-ld=lld-19
26+
- name: Build
27+
if: matrix.os == 'macos-15-intel'
28+
run: make -j4 CC=gcc-15 CXX=g++-15
29+
- name: Build
30+
if: startsWith(matrix.os, 'macos-26')
31+
run: make -j4 CC=$(brew --prefix llvm@20)/bin/clang CXX=$(brew --prefix llvm@20)/bin/clang++
32+
1933
- run: ./tivars_tests

CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
cmake_minimum_required(VERSION 3.21)
22

33
if(DEFINED TIVARS_ENABLE_FUZZING)
44
set(TIVARS_ENABLE_FUZZING "${TIVARS_ENABLE_FUZZING}" CACHE BOOL "Build libFuzzer targets" FORCE)
@@ -22,7 +22,7 @@ endif()
2222

2323
project(tivars_lib_cpp
2424
VERSION 1.3.0
25-
LANGUAGES CXX)
25+
LANGUAGES C CXX)
2626

2727
include(CheckCXXCompilerFlag)
2828
if(MSVC)
@@ -49,6 +49,14 @@ endif()
4949

5050
file(GLOB HEADER_FILES "src/*.h" "src/TypeHandlers/*.h")
5151
file(GLOB COMMON_SOURCE ${HEADER_FILES} "src/*.cpp" "src/TypeHandlers/*.cpp")
52+
set(TIVARS_BUILTIN_TOKENS_SOURCE src/TypeHandlers/BuiltinTokensXml.c)
53+
list(APPEND COMMON_SOURCE ${TIVARS_BUILTIN_TOKENS_SOURCE})
54+
set_source_files_properties(${TIVARS_BUILTIN_TOKENS_SOURCE}
55+
PROPERTIES
56+
C_STANDARD 23
57+
C_STANDARD_REQUIRED ON
58+
C_EXTENSIONS ON
59+
)
5260

5361
# pugixml (vendored)
5462
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/vendor/pugixml)
@@ -71,7 +79,6 @@ target_compile_definitions(tivars_lib_cpp_cli PRIVATE CXXOPTS_NO_REGEX=1)
7179

7280
if(TIVARS_ENABLE_FUZZING)
7381
set(TIVARS_FUZZ_CORPUS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/fuzz/corpus)
74-
set(TIVARS_TOKENS_XML_PATH ${CMAKE_CURRENT_SOURCE_DIR}/ti-toolkit-8x-tokens.xml)
7582

7683
add_custom_target(tivars_fuzzer_seed_corpus
7784
COMMAND ${CMAKE_COMMAND} -E make_directory ${TIVARS_FUZZ_CORPUS_DIR}
@@ -83,7 +90,6 @@ if(TIVARS_ENABLE_FUZZING)
8390
add_dependencies(tivars_lib_cpp_fuzzer tivars_fuzzer_seed_corpus)
8491
target_compile_definitions(tivars_lib_cpp_fuzzer PRIVATE
8592
FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1
86-
TIVARS_TOKENS_XML_PATH="${TIVARS_TOKENS_XML_PATH}"
8793
)
8894
target_compile_options(tivars_lib_cpp_fuzzer PRIVATE
8995
-O1
@@ -212,9 +218,7 @@ if(APPLE)
212218
$<TARGET_OBJECTS:tivars_quicklook_support>
213219
quicklook/PreviewProvider.mm
214220
quicklook/ExtensionMain.m
215-
ti-toolkit-8x-tokens.xml
216221
)
217-
set_source_files_properties(ti-toolkit-8x-tokens.xml PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
218222
set_target_properties(tivars_quicklook_preview_extension PROPERTIES
219223
BUNDLE_EXTENSION appex
220224
OUTPUT_NAME TIVarsQuickLookPreview
@@ -232,7 +236,6 @@ if(APPLE)
232236
$<TARGET_OBJECTS:tivars_quicklook_support>
233237
quicklook/ThumbnailProvider.mm
234238
quicklook/ExtensionMain.m
235-
ti-toolkit-8x-tokens.xml
236239
)
237240
set_target_properties(tivars_quicklook_thumbnail_extension PROPERTIES
238241
BUNDLE_EXTENSION appex

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
CC ?= cc
12
CXXFLAGS := -O3 -std=c++2a -DTH_GDB_SUPPORT=1 -Ivendor/pugixml -W -Wall -Wextra -Werror=write-strings -Werror=redundant-decls -Werror=format -Werror=format-security -Werror=date-time -Werror=return-type -Werror=pointer-arith -Winit-self
3+
CFLAGS := -O3 -std=c2x -W -Wall -Wextra
24

3-
SOURCES_COMMON := $(wildcard src/*.cpp) $(wildcard src/TypeHandlers/*.cpp) vendor/pugixml/pugixml.cpp
5+
SOURCES_COMMON := $(wildcard src/*.cpp) $(wildcard src/TypeHandlers/*.cpp) $(wildcard src/TypeHandlers/*.c) vendor/pugixml/pugixml.cpp
46

57
SOURCES_TESTS := $(SOURCES_COMMON) tests.cpp
68
SOURCES_CLI := $(SOURCES_COMMON) cli/cli.cpp
79

8-
OBJS_TESTS = $(patsubst %.cpp, %.o, $(SOURCES_TESTS))
9-
OBJS_CLI = $(patsubst %.cpp, %.o, $(SOURCES_CLI))
10+
OBJS_TESTS = $(patsubst %.c, %.o, $(patsubst %.cpp, %.o, $(SOURCES_TESTS)))
11+
OBJS_CLI = $(patsubst %.c, %.o, $(patsubst %.cpp, %.o, $(SOURCES_CLI)))
1012

1113
OUTPUT := tivars_tests tivars_cli
1214

@@ -15,6 +17,9 @@ all: $(OUTPUT)
1517
%.o: %.cpp
1618
$(CXX) $(CXXFLAGS) -c $< -o $@
1719

20+
%.o: %.c
21+
$(CC) $(CFLAGS) -c $< -o $@
22+
1823
tivars_tests: $(OBJS_TESTS)
1924
$(CXX) $(CXXFLAGS) $(LFLAGS) $^ -o $@
2025

Makefile.emscripten

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
CC := emcc
12
CXX := em++
23
DEBUG ?= 0
34

@@ -12,14 +13,15 @@ else
1213
endif
1314

1415
# Emscripten stuff
15-
EMFLAGS := --bind -s WASM=1 -s MODULARIZE=1 -s EXPORT_ES6=1 -s EXPORT_NAME="'TIVarsLib'" -s NO_EXIT_RUNTIME=1 -s ASSERTIONS=$(ASSERTIONS) -s DISABLE_EXCEPTION_CATCHING=0 -s EXPORTED_RUNTIME_METHODS="['FS','getExceptionMessage','decrementExceptionRefcount']" $(DEBUG_EMFLAGS) --embed-file ti-toolkit-8x-tokens.xml
16+
EMFLAGS := --bind -s WASM=1 -s MODULARIZE=1 -s EXPORT_ES6=1 -s EXPORT_NAME="'TIVarsLib'" -s NO_EXIT_RUNTIME=1 -s ASSERTIONS=$(ASSERTIONS) -s DISABLE_EXCEPTION_CATCHING=0 -s EXPORTED_RUNTIME_METHODS="['FS','getExceptionMessage','decrementExceptionRefcount']" $(DEBUG_EMFLAGS)
1617

1718
CXXFLAGS := $(OPTFLAGS) -std=c++2a -DTH_GDB_SUPPORT=1 -Ivendor/pugixml -W -Wall -Wextra
19+
CFLAGS := $(OPTFLAGS) -std=c2x -W -Wall -Wextra
1820
LFLAGS := $(OPTFLAGS) $(EMFLAGS)
1921

20-
SOURCES := $(wildcard src/*.cpp) $(wildcard src/TypeHandlers/*.cpp) vendor/pugixml/pugixml.cpp
22+
SOURCES := $(wildcard src/*.cpp) $(wildcard src/TypeHandlers/*.cpp) $(wildcard src/TypeHandlers/*.c) vendor/pugixml/pugixml.cpp
2123

22-
OBJS = $(patsubst %.cpp, %.bc, $(SOURCES))
24+
OBJS = $(patsubst %.c, %.bc, $(patsubst %.cpp, %.bc, $(SOURCES)))
2325

2426
OUTPUT := TIVarsLib
2527

@@ -30,6 +32,9 @@ all: wasm
3032
%.bc: %.cpp
3133
$(CXX) $(CXXFLAGS) -c $< -o $@
3234

35+
%.bc: %.c
36+
$(CC) $(CFLAGS) -c $< -o $@
37+
3338
$(OUTPUT).js: $(OBJS)
3439
$(CXX) $(CXXFLAGS) $(LFLAGS) $^ -o $@
3540

cli/cli.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ int main(int argc, char** argv)
3939
("n,name", "Variable name", cxxopts::value<string>())
4040
("t,type", "Variable type", cxxopts::value<string>())
4141
("m,calc", "Calc. model", cxxopts::value<string>())
42-
("x,xml", "Path to tokens XML file (overrides default ti-toolkit-8x-tokens.xml)", cxxopts::value<string>())
4342
("l,lang", "Language", cxxopts::value<string>()->default_value("en"))
4443
("a,archive", "Archive status", cxxopts::value<bool>())
4544
("r,reindent", "Re-indent", cxxopts::value<bool>())
@@ -214,14 +213,6 @@ int main(int argc, char** argv)
214213
}
215214
else
216215
{
217-
if (result.count("xml"))
218-
{
219-
string xmlFilePath = result["xml"].as<string>();
220-
TH_Tokenized::initTokensFromXMLFilePath(xmlFilePath);
221-
} else {
222-
TH_Tokenized::initTokens();
223-
}
224-
225216
string requestedName;
226217
if (result.count("name"))
227218
{

fuzz/tivars_file_fuzzer.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
#include "../src/TypeHandlers/TypeHandlers.h"
2222
#include "../src/tivarslib_utils.h"
2323

24-
#ifndef TIVARS_TOKENS_XML_PATH
25-
#define TIVARS_TOKENS_XML_PATH "ti-toolkit-8x-tokens.xml"
26-
#endif
27-
2824
namespace
2925
{
3026
constexpr size_t maxInputSize = 2U * 1024U * 1024U;
@@ -47,7 +43,6 @@ namespace
4743
std::call_once(initFlag, []()
4844
{
4945
std::setlocale(LC_ALL, ".UTF-8");
50-
tivars::TypeHandlers::TH_Tokenized::initTokensFromXMLFilePath(TIVARS_TOKENS_XML_PATH);
5146
});
5247
}
5348

quicklook/TIVarsQuickLookSupport.mm

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -693,15 +693,6 @@ void initialize_library()
693693
{
694694
std::call_once(initFlag, []() {
695695
std::setlocale(LC_ALL, ".UTF-8");
696-
NSString* xmlPath = [NSBundle.mainBundle pathForResource:@"ti-toolkit-8x-tokens" ofType:@"xml"];
697-
if (xmlPath)
698-
{
699-
tivars::TypeHandlers::TH_Tokenized::initTokensFromXMLFilePath(xmlPath.UTF8String);
700-
}
701-
else
702-
{
703-
tivars::TypeHandlers::TH_Tokenized::initTokens();
704-
}
705696
});
706697
}
707698

scripts/api_smoke_tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ int main()
2727
}
2828
CPP
2929

30+
cc -std=c2x -c "$ROOT_DIR/src/TypeHandlers/BuiltinTokensXml.c" -o "$TMP_DIR/BuiltinTokensXml.o"
3031
COMMON_SOURCES=("$ROOT_DIR"/src/*.cpp "$ROOT_DIR"/src/TypeHandlers/*.cpp "$ROOT_DIR"/vendor/pugixml/pugixml.cpp)
31-
c++ -std=c++2a -DTH_GDB_SUPPORT=1 -I"$ROOT_DIR" -I"$ROOT_DIR/vendor/pugixml" "${COMMON_SOURCES[@]}" "$TMP_DIR/api_init_smoke.cpp" -o "$TMP_DIR/api_init_smoke"
32+
c++ -std=c++2a -DTH_GDB_SUPPORT=1 -I"$ROOT_DIR" -I"$ROOT_DIR/vendor/pugixml" "${COMMON_SOURCES[@]}" "$TMP_DIR/BuiltinTokensXml.o" "$TMP_DIR/api_init_smoke.cpp" -o "$TMP_DIR/api_init_smoke"
3233
"$TMP_DIR/api_init_smoke"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Part of tivars_lib_cpp
3+
* (C) 2015-2026 Adrien "Adriweb" Bertrand
4+
* https://github.com/adriweb/tivars_lib_cpp
5+
* License: MIT
6+
*/
7+
8+
#include <stddef.h>
9+
10+
const unsigned char tivars_builtin_tokens_xml[] = {
11+
#if defined(__has_embed)
12+
# if __has_embed("../../ti-toolkit-8x-tokens.xml")
13+
# embed "../../ti-toolkit-8x-tokens.xml"
14+
# else
15+
# error "ti-toolkit-8x-tokens.xml not found"
16+
# endif
17+
#else
18+
# error "This compiler does not support #embed"
19+
#endif
20+
};
21+
22+
const size_t tivars_builtin_tokens_xml_size = sizeof(tivars_builtin_tokens_xml);

0 commit comments

Comments
 (0)