Skip to content

Commit 845d821

Browse files
committed
chore: use explicit inject count for shim
1 parent 1e6a384 commit 845d821

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

zig-toolchain.cmake

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ if(ZIG_COMPILER_FLAGS)
106106
endif()
107107

108108
set(_ZIG_COMPILER_INJECTED_FLAGS "-target" "${ZIG_TARGET}" ${_ZIG_EXTRA_FLAGS_LIST})
109+
list(LENGTH _ZIG_COMPILER_INJECTED_FLAGS _ZIG_INJECT_COUNT)
109110
set(_ZIG_INJECTED_C_CODE "")
110111
foreach(_arg IN LISTS _ZIG_COMPILER_INJECTED_FLAGS)
111112
string(REPLACE "\\" "\\\\" _arg_escaped "${_arg}")
@@ -137,8 +138,10 @@ function(generate_shim_binary TOOL_NAME ZIG_SUBCOMMAND INJECT_FLAGS USE_CCACHE)
137138

138139
if(${INJECT_FLAGS})
139140
set(WRAPPER_INJECT_CODE "${_ZIG_INJECTED_C_CODE}")
141+
set(WRAPPER_INJECT_COUNT ${_ZIG_INJECT_COUNT})
140142
else()
141143
set(WRAPPER_INJECT_CODE "")
144+
set(WRAPPER_INJECT_COUNT 0)
142145
endif()
143146

144147
if(${USE_CCACHE} AND _ZIG_CCACHE_EXE)
@@ -159,15 +162,15 @@ function(generate_shim_binary TOOL_NAME ZIG_SUBCOMMAND INJECT_FLAGS USE_CCACHE)
159162
#include <unistd.h>
160163
#endif
161164
162-
#define ZIG_EXE \"${_ZIG_COMPILER_EXE}\"
163-
#define ZIG_CMD \"${ZIG_SUBCOMMAND}\"
164-
#define CCACHE_EXE \"${_ZIG_CCACHE_EXE}\"
165-
#define USE_CCACHE ${WRAPPER_USE_CCACHE}
165+
#define ZIG_EXE \"${_ZIG_COMPILER_EXE}\"
166+
#define ZIG_CMD \"${ZIG_SUBCOMMAND}\"
167+
#define CCACHE_EXE \"${_ZIG_CCACHE_EXE}\"
168+
#define USE_CCACHE ${WRAPPER_USE_CCACHE}
169+
#define INJECT_COUNT ${WRAPPER_INJECT_COUNT}
166170
167171
int main(int argc, char** argv) {
168172
const char* ijlist[] = {${WRAPPER_INJECT_CODE} NULL};
169-
const int ijcount = (int)(sizeof(ijlist) / sizeof(char*)) - 1;
170-
const int exargc = USE_CCACHE + 2 + ijcount + (argc - 1);
173+
const int exargc = USE_CCACHE + 2 + INJECT_COUNT + (argc - 1);
171174
const char** exargv = (const char**)malloc(sizeof(char*) * (size_t)(exargc + 1));
172175
173176
if (!exargv) {
@@ -179,7 +182,7 @@ int main(int argc, char** argv) {
179182
if (USE_CCACHE) { *p++ = CCACHE_EXE; }
180183
*p++ = ZIG_EXE;
181184
*p++ = ZIG_CMD;
182-
for (int i = 0; i < ijcount; ++i) { *p++ = ijlist[i]; }
185+
for (int i = 0; i < INJECT_COUNT; ++i) { *p++ = ijlist[i]; }
183186
for (int i = 1; i < argc; ++i) { *p++ = argv[i]; }
184187
*p = NULL;
185188

0 commit comments

Comments
 (0)