Skip to content

Commit fdc5893

Browse files
committed
Working on examples and example tests
Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
1 parent 2267d70 commit fdc5893

84 files changed

Lines changed: 5820 additions & 1876 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Setup Rust
2+
description: 'Ensure Rust compiler and utilities are available, and setup caching'
3+
4+
inputs:
5+
kind:
6+
type: choice
7+
description: "Whether to install just a default target, or all targets (e.g. for during deployments / wheel building)"
8+
default: "runner"
9+
options:
10+
- runner
11+
- full
12+
- wasm
13+
14+
runs:
15+
using: 'composite'
16+
steps:
17+
- name: Set up Rust
18+
uses: dtolnay/rust-toolchain@stable
19+
with:
20+
toolchain: stable
21+
components: clippy, rustfmt
22+
23+
- name: Setup Rust cache
24+
uses: Swatinem/rust-cache@v2
25+
with:
26+
key: ${{ runner.os }}
27+
28+
- name: Setup cargo cache
29+
uses: actions/cache@v3
30+
with:
31+
path: |
32+
~/.cargo/bin/
33+
~/.cargo/registry/index/
34+
~/.cargo/registry/cache/
35+
~/.cargo/git/db/
36+
**/target
37+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
38+
39+
- run: rustup target add x86_64-unknown-linux-gnu
40+
shell: bash
41+
if: ${{ inputs.kind == 'runner' && runner.os == 'Linux' }}
42+
43+
- run: |
44+
rustup target add aarch64-unknown-linux-gnu
45+
rustup target add x86_64-unknown-linux-gnu
46+
shell: bash
47+
if: ${{ inputs.kind == 'full' && runner.os == 'Linux' }}
48+
49+
- run: rustup target add x86_64-apple-darwin
50+
shell: bash
51+
if: ${{ inputs.kind == 'runner' && runner.os == 'macOS' }}
52+
53+
- run: |
54+
rustup target add aarch64-apple-darwin
55+
rustup target add x86_64-apple-darwin
56+
shell: bash
57+
if: ${{ inputs.kind == 'full' && runner.os == 'macOS' }}
58+
59+
- run: rustup target add x86_64-pc-windows-msvc
60+
shell: bash
61+
if: ${{ inputs.kind == 'runner' && runner.os == 'Windows' }}
62+
63+
- run: |
64+
rustup target add x86_64-pc-windows-msvc
65+
rustup target add aarch64-pc-windows-msvc
66+
shell: bash
67+
if: ${{ inputs.kind == 'full' && runner.os == 'Windows' }}
68+
69+
- run: rustup target add wasm32-unknown-unknown
70+
shell: bash
71+
if: ${{ inputs.kind == 'wasm' }}

.github/workflows/build.yml

Lines changed: 133 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,16 @@ jobs:
211211
# Things to exclude if not a full matrix run #
212212
##############################################
213213
- is-full-run: false
214-
os: windows-2022
215-
cibuildwheel: "cp310"
214+
os: ubuntu-24.04
215+
cibuildwheel: "cp311"
216+
217+
- is-full-run: false
218+
os: ubuntu-24.04
219+
cibuildwheel: "cp312"
220+
221+
- is-full-run: false
222+
os: ubuntu-24.04
223+
cibuildwheel: "cp313"
216224

217225
- is-full-run: false
218226
os: windows-2022
@@ -222,10 +230,9 @@ jobs:
222230
os: windows-2022
223231
cibuildwheel: "cp312"
224232

225-
# avoid unnecessary use of mac resources
226233
- is-full-run: false
227-
os: macos-14
228-
cibuildwheel: "cp310"
234+
os: windows-2022
235+
cibuildwheel: "cp313"
229236

230237
- is-full-run: false
231238
os: macos-14
@@ -235,6 +242,10 @@ jobs:
235242
os: macos-14
236243
cibuildwheel: "cp312"
237244

245+
- is-full-run: false
246+
os: macos-14
247+
cibuildwheel: "cp313"
248+
238249
runs-on: ${{ matrix.os }}
239250

240251
steps:
@@ -417,11 +428,17 @@ jobs:
417428
##############################################
418429
# Things to exclude if not a full matrix run #
419430
##############################################
420-
421-
# Avoid extra resources for windows build
422431
- is-full-run: false
423-
os: windows-2022
424-
python-version: "3.10"
432+
os: ubuntu-24.04
433+
python-version: "3.11"
434+
435+
- is-full-run: false
436+
os: ubuntu-24.04
437+
python-version: "3.12"
438+
439+
- is-full-run: false
440+
os: ubuntu-24.04
441+
python-version: "3.13"
425442

426443
- is-full-run: false
427444
os: windows-2022
@@ -431,10 +448,9 @@ jobs:
431448
os: windows-2022
432449
python-version: "3.12"
433450

434-
# avoid unnecessary use of mac resources
435451
- is-full-run: false
436-
os: macos-14
437-
python-version: "3.10"
452+
os: windows-2022
453+
python-version: "3.13"
438454

439455
- is-full-run: false
440456
os: macos-14
@@ -444,6 +460,10 @@ jobs:
444460
os: macos-14
445461
python-version: "3.12"
446462

463+
- is-full-run: false
464+
os: macos-14
465+
python-version: "3.13"
466+
447467
runs-on: ${{ matrix.os }}
448468

449469
steps:
@@ -515,6 +535,106 @@ jobs:
515535
- name: Python Test Steps
516536
run: make test
517537

538+
####################################################################################################################
539+
#..................................................................................................................#
540+
#..|########|..|########|..../####\....|########|.............../####\...|########\..|########\....................#
541+
#..|########|..|##|......../##/..\##\..|########|............./##/.\##\..|##|../##/..|##|../##/....................#
542+
#.....|##|.....|##|.........\##\..........|##|...............|##|........|##|./##/...|##|./##/.....................#
543+
#.....|##|.....|########|.....\##\........|##|...............|##|........|##||##/....|##||##/......................#
544+
#.....|##|.....|##|.............\##\......|##|...............|##|........|##|........|##|..........................#
545+
#.....|##|.....|##|........\##\../##/.....|##|................\##\./##/..|##|........|##|..........................#
546+
#.....|##|.....|########|...\####/........|##|.................\####/....|##|........|##|..........................#
547+
#..................................................................................................................#
548+
#...|########|...\##\..../##/...../#####\......./|\........./|\....|########\..|##|........|########|..../####\....#
549+
#...|##|..........\##\../##/...../##/.\##\...../#|#\......./#|#\...|##|../##/..|##|........|##|......../##/..\##\..#
550+
#...|##|...........\##\/##/...../##/...\##\...|##|\#\...../#/|##|..|##|./##/...|##|........|##|.........\##\.......#
551+
#...|########|......|####|...../###########\..|##|.\#\.../#/.|##|..|##||##/....|##|........|########|.....\##\.....#
552+
#...|##|.........../##/\##\....|##|.....|##|..|##|..\#\./#/..|##|..|##|........|##|........|##|.............\##\...#
553+
#...|##|........../##/..\##\...|##|.....|##|..|##|...\#|#/...|##|..|##|........|########|..|##|........\##\./##/...#
554+
#...|########|.../##/....\##\..|##|.....|##|..|##|....\|/....|##|..|##|........|########|..|########|...\####/.....#
555+
#.........................................................................................................#
556+
##############################################################
557+
# Build / test C++ examples (05_cpp) #
558+
##############################################################
559+
test_cpp_examples:
560+
needs:
561+
- initialize
562+
- build
563+
564+
strategy:
565+
matrix:
566+
os:
567+
- ubuntu-24.04
568+
- macos-14
569+
example:
570+
- 1_cpp_node
571+
- 2_cpp_node_with_struct
572+
- 3_cpp_adapter
573+
- 4_c_api_adapter
574+
- 5_c_api_adapter_rust
575+
python-version:
576+
- "3.10"
577+
578+
runs-on: ${{ matrix.os }}
579+
580+
steps:
581+
- name: Checkout
582+
uses: actions/checkout@v6
583+
with:
584+
submodules: recursive
585+
586+
- name: Set up Python ${{ matrix.python-version }}
587+
uses: ./.github/actions/setup-python
588+
with:
589+
version: '${{ matrix.python-version }}'
590+
cibuildwheel: false
591+
592+
- name: Set up Caches
593+
uses: ./.github/actions/setup-caches
594+
595+
- name: Install python dependencies
596+
run: make requirements
597+
598+
- name: Download wheel
599+
uses: actions/download-artifact@v7
600+
with:
601+
name: csp-dist-${{ runner.os }}-${{ runner.arch }}-${{ matrix.python-version }}
602+
603+
########
604+
# Linux
605+
- name: Install wheel (Linux)
606+
run: |
607+
python -m pip install -U *manylinux*.whl
608+
if: ${{ runner.os == 'Linux' }}
609+
610+
- name: Install build tools (Linux)
611+
run: sudo apt-get install -y cmake build-essential
612+
if: ${{ runner.os == 'Linux' }}
613+
614+
########
615+
# MacOS
616+
- name: Install wheel (OSX arm)
617+
run: |
618+
python -m pip install -U *arm64*.whl
619+
if: ${{ runner.os == 'macOS' && runner.arch == 'ARM64' }}
620+
621+
- name: Install wheel (OSX x86)
622+
run: |
623+
python -m pip install -U *x86*.whl
624+
if: ${{ runner.os == 'macOS' && runner.arch == 'X64' }}
625+
626+
##########
627+
# Steps for Rust depend C API Rust Example (5_c_api_adapter_rust)
628+
- name: Setup Rust
629+
uses: ./.github/actions/setup-rust
630+
if: ${{ matrix.example == '5_c_api_adapter_rust' }}
631+
632+
- name: Build example ${{ matrix.example }} and run tests
633+
run: |
634+
cd examples/05_cpp/${{ matrix.example }}
635+
hatch-build --hooks-only -t wheel
636+
python -m pytest -vvv .
637+
518638
################################################################
519639
#..............................................................#
520640
#..|########|..|########|..../####\....|########|..............#
@@ -731,6 +851,7 @@ jobs:
731851
- test
732852
- test_sdist
733853
- test_dependencies
854+
- test_cpp_examples
734855

735856
if: startsWith(github.ref, 'refs/tags/v')
736857
runs-on: ubuntu-24.04

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ lint-cpp:
4444

4545
lint-docs:
4646
python -m mdformat --check docs/wiki/ README.md examples/
47-
python -m codespell_lib docs/wiki/ README.md examples/ --skip "*.cpp,*.h"
47+
python -m codespell_lib docs/wiki/ README.md examples/ --skip "*.cpp,*.h,*.d,*.make,*.internal,CMakeConfigureLog.yaml"
4848

4949
# lint: lint-py lint-cpp ## run lints
5050
lint: lint-py lint-docs ## run lints
@@ -62,7 +62,7 @@ fix-cpp:
6262

6363
fix-docs:
6464
python -m mdformat docs/wiki/ README.md examples/
65-
python -m codespell_lib --write docs/wiki/ README.md examples/ --skip "*.cpp,*.h"
65+
python -m codespell_lib --write docs/wiki/ README.md examples/ --skip "*.cpp,*.h,*.d,*.make,*.internal,CMakeConfigureLog.yaml"
6666

6767
fix: fix-py fix-cpp fix-docs ## run autofixers
6868

cpp/csp/core/Platform.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@
2828
#define CSPIMPL_EXPORT __declspec(dllimport)
2929
#endif
3030

31+
// C API export macro - used for ABI-stable C functions
32+
// On Windows: export from cspimpl.dll
33+
// On Unix: ensure symbols have default visibility
34+
#ifdef CSPIMPL_EXPORTS
35+
#define CSP_C_API_EXPORT __declspec(dllexport)
36+
#else
37+
#define CSP_C_API_EXPORT __declspec(dllimport)
38+
#endif
39+
3140
#define START_PACKED __pragma( pack(push, 1) )
3241
#define END_PACKED __pragma( pack(pop))
3342

@@ -73,7 +82,7 @@ inline uint8_t clz(uint8_t n) { return clz(static_cast<uint32_t>(n)) - 24; }
7382

7483
template<typename U, std::enable_if_t<std::is_unsigned<U>::value, bool> = true>
7584
inline uint8_t ffs(U n)
76-
{
85+
{
7786
unsigned long index = 0;
7887
if (_BitScanForward(&index, n))
7988
return index + 1;
@@ -93,6 +102,9 @@ inline uint8_t ffs(uint64_t n)
93102
#define CSPIMPL_EXPORT
94103
#define CSPTYPESIMPL_EXPORT
95104

105+
// C API export macro - ensure symbols have default visibility for external use
106+
#define CSP_C_API_EXPORT __attribute__((visibility("default")))
107+
96108
#define DLL_LOCAL __attribute__ ((visibility ("hidden")))
97109

98110
#define START_PACKED

cpp/csp/core/Time.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ inline std::string TimeDelta::asString() const
110110
int32_t s = seconds();
111111
int32_t n = nanoseconds();
112112

113-
int idx = d ? sprintf( buf, "%d %s ", d, d == 1 ? "day" : "days" ) : 0;
114-
idx += sprintf( buf + idx, "%02d:%02d:%02d", h, m, s );
113+
int idx = d ? snprintf( buf, sizeof(buf), "%d %s ", d, d == 1 ? "day" : "days" ) : 0;
114+
idx += snprintf( buf + idx, sizeof(buf) - idx, "%02d:%02d:%02d", h, m, s );
115115
if( n )
116-
sprintf( buf + idx, ".%09d", n );
116+
snprintf( buf + idx, sizeof(buf) - idx, ".%09d", n );
117117
return buf;
118118
}
119119

@@ -306,7 +306,7 @@ inline Date Date::today()
306306
inline std::string Date::asYYYYMMDD() const
307307
{
308308
char buf[32];
309-
sprintf( buf, "%04d%02d%02d", year(), month(), day() );
309+
snprintf( buf, sizeof(buf), "%04d%02d%02d", year(), month(), day() );
310310
return buf;
311311
}
312312

@@ -416,7 +416,7 @@ inline Time& Time::operator -=( const TimeDelta & delta )
416416
inline std::string Time::asString() const
417417
{
418418
char buf[64];
419-
sprintf( buf, "%02d:%02d:%02d.%09d", hour(), minute(), second(), nanosecond() );
419+
snprintf( buf, sizeof(buf), "%02d:%02d:%02d.%09d", hour(), minute(), second(), nanosecond() );
420420
return buf;
421421
}
422422

cpp/csp/engine/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set(CSP_TYPES_SOURCE_FILES
2020

2121
# C API headers (ABI-stable interface)
2222
set(CSP_C_API_HEADERS
23+
c/CspExport.h
2324
c/CspError.h
2425
c/CspTime.h
2526
c/CspString.h
@@ -61,6 +62,7 @@ set(ENGINE_PUBLIC_HEADERS
6162
PushEvent.h
6263
PullInputAdapter.h
6364
PushInputAdapter.h
65+
PushInputAdapterExtern.h
6466
PushPullInputAdapter.h
6567
RootEngine.h
6668
Scheduler.h
@@ -93,6 +95,7 @@ set(ENGINE_SOURCE_FILES
9395
AdapterManagerExtern.cpp
9496
DictionaryExtern.cpp
9597
StructExtern.cpp
98+
PushInputAdapterExtern.cpp
9699
PendingPushEvents.cpp
97100
PushPullInputAdapter.cpp
98101
RootEngine.cpp

0 commit comments

Comments
 (0)