@@ -130,107 +130,8 @@ public static function getEnvironment(): array
130130
131131 private function createZigCcScript (string $ bin_dir ): void
132132 {
133- $ script_content = <<<'EOF'
134- #!/usr/bin/env bash
135-
136- LIBDIR="$(realpath "$(dirname "$(gcc -print-file-name=libc.so)")")"
137- SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
138- BUILDROOT_ABS="$(realpath "$SCRIPT_DIR/../../buildroot/include" 2>/dev/null || echo "")"
139- PARSED_ARGS=()
140-
141- while [[ $# -gt 0 ]]; do
142- case "$1" in
143- -isystem)
144- shift
145- ARG="$1"
146- [[ -n "$ARG" ]] && shift || break
147- ARG_ABS="$(realpath "$ARG" 2>/dev/null || echo "")"
148- if [[ -n "$ARG_ABS" && "$ARG_ABS" == "$BUILDROOT_ABS" ]]; then
149- PARSED_ARGS+=("-I$ARG")
150- else
151- PARSED_ARGS+=("-isystem" "$ARG")
152- fi
153- ;;
154- -isystem*)
155- ARG="${1#-isystem}"
156- shift
157- ARG_ABS="$(realpath "$ARG" 2>/dev/null || echo "")"
158- if [[ -n "$ARG_ABS" && "$ARG_ABS" == "$BUILDROOT_ABS" ]]; then
159- PARSED_ARGS+=("-I$ARG")
160- else
161- PARSED_ARGS+=("-isystem$ARG")
162- fi
163- ;;
164- *)
165- PARSED_ARGS+=("$1")
166- shift
167- ;;
168- esac
169- done
170-
171- SPC_TARGET_WAS_SET=1
172- if [ -z "${SPC_TARGET+x}" ]; then
173- SPC_TARGET_WAS_SET=0
174- fi
175-
176- UNAME_M="$(uname -m)"
177- UNAME_S="$(uname -s)"
178-
179- case "$UNAME_M" in
180- x86_64) ARCH="x86_64" ;;
181- aarch64|arm64) ARCH="aarch64" ;;
182- *) echo "Unsupported architecture: $UNAME_M" >&2; exit 1 ;;
183- esac
184-
185- case "$UNAME_S" in
186- Linux) OS="linux" ;;
187- Darwin) OS="macos" ;;
188- *) echo "Unsupported OS: $UNAME_S" >&2; exit 1 ;;
189- esac
190-
191- SPC_TARGET="${SPC_TARGET:-$ARCH-$OS}"
192-
193- if [ "$SPC_LIBC" = "glibc" ]; then
194- SPC_LIBC="gnu"
195- fi
196-
197- if [ "$SPC_TARGET_WAS_SET" -eq 0 ] && [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then
198- exec zig cc "${PARSED_ARGS[@]}"
199- elif [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then
200- exec zig cc -target ${SPC_TARGET} "${PARSED_ARGS[@]}"
201- else
202- TARGET="${SPC_TARGET}-${SPC_LIBC}"
203- [ -n "$SPC_LIBC_VERSION" ] && TARGET="${TARGET}.${SPC_LIBC_VERSION}"
204-
205- output=$(zig cc -target "$TARGET" -L"$LIBDIR" -lstdc++ "${PARSED_ARGS[@]}" 2>&1)
206- status=$?
207-
208- filtered_output=$(echo "$output" | grep -v "version '.*' in target triple")
209-
210- if [ $status -eq 0 ]; then
211- echo "$filtered_output"
212- exit 0
213- fi
214-
215- if echo "$output" | grep -q "version '.*' in target triple"; then
216- TARGET_FALLBACK="${SPC_TARGET}-${SPC_LIBC}"
217- output=$(zig cc -target "$TARGET_FALLBACK" -L"$LIBDIR" -lstdc++ "${PARSED_ARGS[@]}" 2>&1)
218- status=$?
219-
220- filtered_output=$(echo "$output" | grep -v "version '.*' in target triple")
221-
222- if [ $status -eq 0 ]; then
223- echo "$filtered_output"
224- exit 0
225- else
226- exec zig cc -target "$TARGET_FALLBACK" "${PARSED_ARGS[@]}"
227- fi
228- else
229- echo "$filtered_output"
230- exec zig cc -target "$TARGET" "${PARSED_ARGS[@]}"
231- fi
232- fi
233- EOF;
133+ $ script_path = __DIR__ . '/../scripts/zig-cc.sh ' ;
134+ $ script_content = file_get_contents ($ script_path );
234135
235136 file_put_contents ("{$ bin_dir }/zig-cc " , $ script_content );
236137 chmod ("{$ bin_dir }/zig-cc " , 0755 );
0 commit comments