Skip to content

Commit 2104c69

Browse files
authored
Merge pull request #13 from dill-lk/codex/refactor-code-for-maximum-performance-lggui1
Codex-generated pull request
2 parents 29fab62 + 78a7adf commit 2104c69

4 files changed

Lines changed: 39 additions & 3 deletions

File tree

.github/workflows/build.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,24 @@ jobs:
8585
shell: pwsh
8686
run: |
8787
choco install mingw -y
88-
echo "CXX=C:\\ProgramData\\chocolatey\\lib\\mingw\\tools\\install\\mingw64\\bin\\g++.exe" >> $env:GITHUB_ENV
88+
$candidates = @(
89+
"C:\\ProgramData\\chocolatey\\lib\\mingw\\tools\\install\\mingw64\\bin\\g++.exe",
90+
"C:\\msys64\\mingw64\\bin\\g++.exe"
91+
)
92+
$found = $null
93+
foreach ($c in $candidates) {
94+
if (Test-Path $c) { $found = $c; break }
95+
}
96+
if (-not $found) {
97+
$cmd = Get-Command g++ -ErrorAction SilentlyContinue
98+
if ($cmd) { $found = $cmd.Source }
99+
}
100+
if (-not $found) {
101+
throw "No g++ compiler found after MinGW install"
102+
}
103+
$bindir = Split-Path $found -Parent
104+
echo "$bindir" >> $env:GITHUB_PATH
105+
echo "CXX=$found" >> $env:GITHUB_ENV
89106
90107
- name: Verify C++ backend availability
91108
run: python gravity_lang_interpreter.py backends

cpp/gravity_compiler.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,11 @@ int main(int argc, char** argv) {
313313
out.close();
314314

315315
if (!build.empty()) {
316-
std::string cmd = cxx + " -O3 -std=c++17 \"" + emit + "\" -o \"" + build + "\"";
316+
std::string cmd = cxx + " -O3 -std=c++17 ";
317+
#ifdef _WIN32
318+
cmd += "-static -static-libstdc++ -static-libgcc ";
319+
#endif
320+
cmd += "\"" + emit + "\" -o \"" + build + "\"";
317321
int rc = std::system(cmd.c_str());
318322
if (rc != 0) throw std::runtime_error("compiler failed: " + cmd);
319323
std::cout << "built executable: " << build << "\n";

gravity_lang_interpreter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,10 @@ def build_cpp_compiler_executable(name: str = "gravityc", outdir: str = "dist",
23872387
if not source.exists():
23882388
raise RuntimeError(f"Native compiler source not found: {source}")
23892389

2390-
cmd = [str(compiler), "-O3", "-std=c++17", str(source), "-o", str(target)]
2390+
cmd = [str(compiler), "-O3", "-std=c++17"]
2391+
if sys.platform.startswith("win"):
2392+
cmd += ["-static", "-static-libstdc++", "-static-libgcc"]
2393+
cmd += [str(source), "-o", str(target)]
23912394
subprocess.run(cmd, check=True)
23922395
return target
23932396

tests/test_interpreter.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ def test_build_cpp_compiler_executable_invokes_compiler(self):
309309
cmd = run_mock.call_args[0][0]
310310
self.assertIn("cpp/gravity_compiler.cpp", cmd)
311311

312+
def test_build_cpp_compiler_executable_windows_static_link_flags(self):
313+
with (
314+
patch("gravity_lang_interpreter.shutil.which", side_effect=["C:/mingw/bin/g++.exe"]),
315+
patch("gravity_lang_interpreter.subprocess.run") as run_mock,
316+
patch.object(gli.sys, "platform", "win32"),
317+
):
318+
build_cpp_compiler_executable(name="gravityc-test", outdir="dist")
319+
cmd = run_mock.call_args[0][0]
320+
self.assertIn("-static", cmd)
321+
self.assertIn("-static-libstdc++", cmd)
322+
self.assertIn("-static-libgcc", cmd)
323+
312324
def test_cli_build_cpp_exe_command(self):
313325
with (
314326
patch("gravity_lang_interpreter.build_cpp_compiler_executable", return_value=Path("dist/gravityc")),

0 commit comments

Comments
 (0)