Skip to content

Commit f40beb4

Browse files
committed
fix(ci): unbreak linux package build and stabilize ios bridge snapshot
- bin.js: guard the dist.cmake write with `existsSync(prebuilt)`. On non-darwin runners createLib + createXCFramework early-return for ios targets, so `<output>/prebuilt/` never exists; the template write was crashing with ENOENT and failing `cppjs build -p ios` on linux CI. When prebuilt artifacts are absent the template is meaningless, so silently skip. - ci snapshot: rename cppjs-sample-mobile-reactnative-cli/ci/.cppjs/... -> cppjs-sample-mobile-reactnative-cli/ci/cppjs-snapshot/... so that pnpm clear:cache:samples (and any future variant matching `**/.cppjs`) cannot accidentally wipe the bridge fixtures used by the iOS test workflow. Restore the four files that were lost in the previous deletion. - test-ios-sample.yml: copy snapshot contents into the sample's `.cppjs/` using `mkdir -p` + trailing `/.` so the restore never nests `cppjs-snapshot/` inside `.cppjs/` regardless of pre-existing state.
1 parent 8a0b918 commit f40beb4

6 files changed

Lines changed: 262 additions & 6 deletions

File tree

.github/workflows/test-ios-sample.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ jobs:
7474
curl -fsSL "https://get.maestro.mobile.dev" | bash
7575
echo "$HOME/.maestro/bin" >> $GITHUB_PATH
7676
- name: Restore cached bridge files
77-
run: cp -r ./cppjs-samples/cppjs-sample-mobile-reactnative-cli/ci/.cppjs ./cppjs-samples/cppjs-sample-mobile-reactnative-cli
77+
run: |
78+
mkdir -p ./cppjs-samples/cppjs-sample-mobile-reactnative-cli/.cppjs
79+
cp -r ./cppjs-samples/cppjs-sample-mobile-reactnative-cli/ci/cppjs-snapshot/. ./cppjs-samples/cppjs-sample-mobile-reactnative-cli/.cppjs/
7880
- name: Build cppjs-sample-lib-prebuilt-matrix
7981
run: pnpm --filter=@cpp.js/sample-lib-prebuilt-matrix run build:ios
8082
- name: Pod install

cppjs-core/cpp.js/src/bin.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,13 @@ function buildLib(targetParams) {
315315
}
316316
}
317317

318-
const distCmakeContent = fs.readFileSync(`${state.config.paths.cli}/assets/cmake/dist.cmake`, { encoding: 'utf8', flag: 'r' })
319-
.replace('___PROJECT_NAME___', state.config.general.name)
320-
.replace('___PROJECT_HOST___', targets.map((t) => t.path).join(';'))
321-
.replace('___PROJECT_LIBS___', state.config.export.libName.join(';'));
322-
fs.writeFileSync(`${state.config.paths.output}/prebuilt/CMakeLists.txt`, distCmakeContent);
318+
if (fs.existsSync(`${state.config.paths.output}/prebuilt`)) {
319+
const distCmakeContent = fs.readFileSync(`${state.config.paths.cli}/assets/cmake/dist.cmake`, { encoding: 'utf8', flag: 'r' })
320+
.replace('___PROJECT_NAME___', state.config.general.name)
321+
.replace('___PROJECT_HOST___', targets.map((t) => t.path).join(';'))
322+
.replace('___PROJECT_LIBS___', state.config.export.libName.join(';'));
323+
fs.writeFileSync(`${state.config.paths.output}/prebuilt/CMakeLists.txt`, distCmakeContent);
324+
}
323325
}
324326

325327
async function createWasmJs(targetParams) {
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
/* ----------------------------------------------------------------------------
2+
* This file was automatically generated by SWIG (https://www.swig.org).
3+
* Version 4.2.1
4+
*
5+
* Do not make changes to this file unless you know what you are doing - modify
6+
* the SWIG interface file instead.
7+
* ----------------------------------------------------------------------------- */
8+
/* -----------------------------------------------------------------------------
9+
* This section contains generic SWIG labels for method/variable
10+
* declarations/attributes, and other compiler dependent labels.
11+
* ----------------------------------------------------------------------------- */
12+
13+
/* template workaround for compilers that cannot correctly implement the C++ standard */
14+
#ifndef SWIGTEMPLATEDISAMBIGUATOR
15+
# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
16+
# define SWIGTEMPLATEDISAMBIGUATOR template
17+
# elif defined(__HP_aCC)
18+
/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
19+
/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
20+
# define SWIGTEMPLATEDISAMBIGUATOR template
21+
# else
22+
# define SWIGTEMPLATEDISAMBIGUATOR
23+
# endif
24+
#endif
25+
26+
/* inline attribute */
27+
#ifndef SWIGINLINE
28+
# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
29+
# define SWIGINLINE inline
30+
# else
31+
# define SWIGINLINE
32+
# endif
33+
#endif
34+
35+
/* attribute recognised by some compilers to avoid 'unused' warnings */
36+
#ifndef SWIGUNUSED
37+
# if defined(__GNUC__)
38+
# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
39+
# define SWIGUNUSED __attribute__ ((__unused__))
40+
# else
41+
# define SWIGUNUSED
42+
# endif
43+
# elif defined(__ICC)
44+
# define SWIGUNUSED __attribute__ ((__unused__))
45+
# else
46+
# define SWIGUNUSED
47+
# endif
48+
#endif
49+
50+
#ifndef SWIG_MSC_UNSUPPRESS_4505
51+
# if defined(_MSC_VER)
52+
# pragma warning(disable : 4505) /* unreferenced local function has been removed */
53+
# endif
54+
#endif
55+
56+
#ifndef SWIGUNUSEDPARM
57+
# ifdef __cplusplus
58+
# define SWIGUNUSEDPARM(p)
59+
# else
60+
# define SWIGUNUSEDPARM(p) p SWIGUNUSED
61+
# endif
62+
#endif
63+
64+
/* internal SWIG method */
65+
#ifndef SWIGINTERN
66+
# define SWIGINTERN static SWIGUNUSED
67+
#endif
68+
69+
/* internal inline SWIG method */
70+
#ifndef SWIGINTERNINLINE
71+
# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
72+
#endif
73+
74+
/* exporting methods */
75+
#if defined(__GNUC__)
76+
# if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
77+
# ifndef GCC_HASCLASSVISIBILITY
78+
# define GCC_HASCLASSVISIBILITY
79+
# endif
80+
# endif
81+
#endif
82+
83+
#ifndef SWIGEXPORT
84+
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
85+
# if defined(STATIC_LINKED)
86+
# define SWIGEXPORT
87+
# else
88+
# define SWIGEXPORT __declspec(dllexport)
89+
# endif
90+
# else
91+
# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
92+
# define SWIGEXPORT __attribute__ ((visibility("default")))
93+
# else
94+
# define SWIGEXPORT
95+
# endif
96+
# endif
97+
#endif
98+
99+
/* calling conventions for Windows */
100+
#ifndef SWIGSTDCALL
101+
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
102+
# define SWIGSTDCALL __stdcall
103+
# else
104+
# define SWIGSTDCALL
105+
# endif
106+
#endif
107+
108+
/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
109+
#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
110+
# define _CRT_SECURE_NO_DEPRECATE
111+
#endif
112+
113+
/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
114+
#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
115+
# define _SCL_SECURE_NO_DEPRECATE
116+
#endif
117+
118+
/* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */
119+
#if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES)
120+
# define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
121+
#endif
122+
123+
/* Intel's compiler complains if a variable which was never initialised is
124+
* cast to void, which is a common idiom which we use to indicate that we
125+
* are aware a variable isn't used. So we just silence that warning.
126+
* See: https://github.com/swig/swig/issues/192 for more discussion.
127+
*/
128+
#ifdef __INTEL_COMPILER
129+
# pragma warning disable 592
130+
#endif
131+
132+
#if __cplusplus >=201103L
133+
# define SWIG_NULLPTR nullptr
134+
#else
135+
# define SWIG_NULLPTR NULL
136+
#endif
137+
138+
/* -----------------------------------------------------------------------------
139+
* swigcompat.swg
140+
*
141+
* Macros to provide support compatibility with older C and C++ standards.
142+
* ----------------------------------------------------------------------------- */
143+
144+
/* C99 and C++11 should provide snprintf, but define SWIG_NO_SNPRINTF
145+
* if you're missing it.
146+
*/
147+
#if ((defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) || \
148+
(defined __cplusplus && __cplusplus >= 201103L) || \
149+
defined SWIG_HAVE_SNPRINTF) && \
150+
!defined SWIG_NO_SNPRINTF
151+
# define SWIG_snprintf(O,S,F,A) snprintf(O,S,F,A)
152+
# define SWIG_snprintf2(O,S,F,A,B) snprintf(O,S,F,A,B)
153+
#else
154+
/* Fallback versions ignore the buffer size, but most of our uses either have a
155+
* fixed maximum possible size or dynamically allocate a buffer that's large
156+
* enough.
157+
*/
158+
# define SWIG_snprintf(O,S,F,A) sprintf(O,F,A)
159+
# define SWIG_snprintf2(O,S,F,A,B) sprintf(O,F,A,B)
160+
#endif
161+
162+
#include <emscripten/bind.h>
163+
164+
#ifdef __cplusplus
165+
#include <utility>
166+
/* SwigValueWrapper is described in swig.swg */
167+
template<typename T> class SwigValueWrapper {
168+
struct SwigSmartPointer {
169+
T *ptr;
170+
SwigSmartPointer(T *p) : ptr(p) { }
171+
~SwigSmartPointer() { delete ptr; }
172+
SwigSmartPointer& operator=(SwigSmartPointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }
173+
void reset(T *p) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = p; }
174+
} pointer;
175+
SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs);
176+
SwigValueWrapper(const SwigValueWrapper<T>& rhs);
177+
public:
178+
SwigValueWrapper() : pointer(0) { }
179+
SwigValueWrapper& operator=(const T& t) { SwigSmartPointer tmp(new T(t)); pointer = tmp; return *this; }
180+
#if __cplusplus >=201103L
181+
SwigValueWrapper& operator=(T&& t) { SwigSmartPointer tmp(new T(std::move(t))); pointer = tmp; return *this; }
182+
operator T&&() const { return std::move(*pointer.ptr); }
183+
#else
184+
operator T&() const { return *pointer.ptr; }
185+
#endif
186+
T *operator&() const { return pointer.ptr; }
187+
static void reset(SwigValueWrapper& t, T *p) { t.pointer.reset(p); }
188+
};
189+
190+
/*
191+
* SwigValueInit() is a generic initialisation solution as the following approach:
192+
*
193+
* T c_result = T();
194+
*
195+
* doesn't compile for all types for example:
196+
*
197+
* unsigned int c_result = unsigned int();
198+
*/
199+
template <typename T> T SwigValueInit() {
200+
return T();
201+
}
202+
203+
#if __cplusplus >=201103L
204+
# define SWIG_STD_MOVE(OBJ) std::move(OBJ)
205+
#else
206+
# define SWIG_STD_MOVE(OBJ) OBJ
207+
#endif
208+
209+
#endif
210+
211+
212+
#include "native.h"
213+
214+
EMSCRIPTEN_BINDINGS(Native) {
215+
emscripten::class_<Native>("Native")
216+
.smart_ptr<std::shared_ptr<Native>>("Native")
217+
.class_function("sample", &Native::sample)
218+
.smart_ptr_constructor("Native", &std::make_shared<Native>)
219+
;
220+
}
221+
222+
EMSCRIPTEN_BINDINGS(Functions_NATIVE) {
223+
emscripten::register_vector<std::shared_ptr<Native>>("VectorNative");
224+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["VectorNative", "Native"]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef _NATIVE_I
2+
#define _NATIVE_I
3+
4+
%module NATIVE
5+
6+
%{
7+
#include "native.h"
8+
%}
9+
10+
%feature("shared_ptr");
11+
%feature("polymorphic_shared_ptr");
12+
13+
%include "native.h"
14+
15+
#endif
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"hashes": {
3+
"/Users/runner/work/cpp.js/cpp.js/cppjs-samples/cppjs-sample-mobile-reactnative-cli/src/native/native.h": "d105082c6e8c8652ea461e161c501e824b6b625f7b819490102c5c0699744249",
4+
"/Users/runner/work/cpp.js/cpp.js/cppjs-samples/cppjs-sample-mobile-reactnative-cli/.cppjs/build/interface/native.i": "eab7d231467438ee3e5f5af1c3ae64919c0514393461653981fb40f26b5edad3"
5+
},
6+
"interfaces": {
7+
"/Users/runner/work/cpp.js/cpp.js/cppjs-samples/cppjs-sample-mobile-reactnative-cli/src/native/native.h": "/Users/runner/work/cpp.js/cpp.js/cppjs-samples/cppjs-sample-mobile-reactnative-cli/.cppjs/build/interface/native.i"
8+
},
9+
"bridges": {
10+
"/Users/runner/work/cpp.js/cpp.js/cppjs-samples/cppjs-sample-mobile-reactnative-cli/.cppjs/build/interface/native.i": "/Users/runner/work/cpp.js/cpp.js/cppjs-samples/cppjs-sample-mobile-reactnative-cli/.cppjs/build/bridge/native.i.cpp"
11+
}
12+
}

0 commit comments

Comments
 (0)