Skip to content

Commit 2fe3378

Browse files
committed
checkWindowsDLLs: copy from bundled libs only, remove all MSYS2 references
1 parent ed04c59 commit 2fe3378

2 files changed

Lines changed: 23 additions & 96 deletions

File tree

mode/CppMode.jar

-945 Bytes
Binary file not shown.

src/java/CppBuild.java

Lines changed: 23 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -652,115 +652,42 @@ private boolean windowsLibsNowPresent(java.util.List<String> searchDirs, String[
652652
}
653653

654654
private void checkWindowsDLLs(RunnerListener listener, File binary) throws Exception {
655-
String[] required = { "glfw3.dll", "glew32.dll" };
656-
String[] allDlls = { "glfw3.dll", "glew32.dll",
655+
String[] allDlls = { "glfw3.dll", "glew32.dll",
657656
"libgcc_s_seh-1.dll", "libstdc++-6.dll", "libwinpthread-1.dll" };
658-
String[] msysDirs = { "C:\\msys64\\mingw64\\bin", "C:\\msys2\\mingw64\\bin" };
659-
File bundledLibsDir = new File(runtimeDir.getParentFile(), "libs/windows-x64");
660-
java.util.List<String> searchDirs = new java.util.ArrayList<>();
661-
searchDirs.add(binary.getParent());
662-
if (bundledLibsDir.exists()) searchDirs.add(bundledLibsDir.getAbsolutePath());
663-
for (String d : msysDirs) searchDirs.add(d);
664-
String path = System.getenv("PATH");
665-
if (path != null) for (String p2 : path.split(";")) searchDirs.add(p2);
666-
java.util.List<String> copyDirs = new java.util.ArrayList<>();
667-
if (bundledLibsDir.exists()) copyDirs.add(bundledLibsDir.getAbsolutePath());
668-
for (String d : msysDirs) copyDirs.add(d);
657+
String[] required = { "glfw3.dll", "glew32.dll" };
658+
659+
// Bundled DLLs are in libs/windows-x64 -- copy them next to the binary
660+
File bundledDir = new File(runtimeDir.getParentFile(), "libs/windows-x64");
661+
File binaryDir = new File(binary.getParent());
662+
binaryDir.mkdirs();
663+
669664
for (String dll : allDlls) {
670-
File dest = new File(binary.getParent(), dll);
665+
File dest = new File(binaryDir, dll);
671666
if (dest.exists()) continue;
672-
for (String dir : copyDirs) {
673-
File src2 = new File(dir, dll);
674-
if (src2.exists()) {
675-
try { java.nio.file.Files.copy(src2.toPath(), dest.toPath(),
676-
java.nio.file.StandardCopyOption.REPLACE_EXISTING); }
677-
catch (Exception ignored) {}
678-
break;
667+
File src2 = new File(bundledDir, dll);
668+
if (src2.exists()) {
669+
try { java.nio.file.Files.copy(src2.toPath(), dest.toPath(),
670+
java.nio.file.StandardCopyOption.REPLACE_EXISTING); }
671+
catch (Exception e) {
672+
System.err.println("[CppMode] Failed to copy " + dll + ": " + e.getMessage());
679673
}
680674
}
681675
}
676+
677+
// Verify required DLLs are now present
682678
java.util.List<String> missing = new java.util.ArrayList<>();
683-
outer:
684679
for (String dll : required) {
685-
for (String dir : searchDirs)
686-
if (new File(dir, dll).exists()) continue outer;
687-
missing.add(dll);
680+
if (!new File(binaryDir, dll).exists() && !new File(bundledDir, dll).exists())
681+
missing.add(dll);
688682
}
689683
if (missing.isEmpty()) return;
690684

691-
// Try the guided installer first.
692-
if (InstallWizard.run(listener)) {
693-
if (windowsLibsNowPresent(searchDirs, required)) return;
694-
}
695-
696-
int choice = javax.swing.JOptionPane.showConfirmDialog(null,
697-
"Missing libraries: " + String.join(", ", missing) + "\n\n" +
698-
"C++ Mode requires GLFW and GLEW to run sketches.\n" +
699-
"Click OK to install them automatically via MSYS2.",
700-
"Missing Libraries", javax.swing.JOptionPane.OK_CANCEL_OPTION,
701-
javax.swing.JOptionPane.WARNING_MESSAGE);
702-
703-
if (choice != javax.swing.JOptionPane.OK_OPTION) return;
704-
705-
// Find MSYS2 pacman
706-
String pacman = null;
707-
for (String p : new String[]{
708-
"C:\\msys64\\usr\\bin\\pacman.exe",
709-
"C:\\msys2\\usr\\bin\\pacman.exe"})
710-
if (new File(p).exists()) { pacman = p; break; }
711-
712-
if (pacman == null) {
713-
try { java.awt.Desktop.getDesktop().browse(new java.net.URI("https://www.msys2.org")); }
714-
catch (Exception ignored) {}
715-
javax.swing.JOptionPane.showMessageDialog(null,
716-
"MSYS2 not found. Please install it from https://www.msys2.org\n\n" +
717-
"Then open MSYS2 MinGW 64-bit and run:\n" +
718-
" pacman -S mingw-w64-x86_64-glfw mingw-w64-x86_64-glew\n\n" +
719-
"Then restart Processing.",
720-
"Install MSYS2", javax.swing.JOptionPane.INFORMATION_MESSAGE);
721-
return;
722-
}
723-
724-
final String finalPacman = pacman;
725-
new Thread(() -> {
726-
try {
727-
listener.statusNotice("Installing GLFW and GLEW via MSYS2...");
728-
ProcessBuilder pb = new ProcessBuilder(finalPacman, "-S", "--noconfirm",
729-
"mingw-w64-x86_64-glfw", "mingw-w64-x86_64-glew");
730-
pb.redirectErrorStream(true);
731-
Process p = pb.start();
732-
try (java.io.BufferedReader br = new java.io.BufferedReader(
733-
new java.io.InputStreamReader(p.getInputStream()))) {
734-
String line; while ((line = br.readLine()) != null) System.out.println(line);
735-
}
736-
if (p.waitFor() == 0) {
737-
// Copy DLLs next to binary
738-
for (String dll : new String[]{ "glfw3.dll","glew32.dll",
739-
"libgcc_s_seh-1.dll","libstdc++-6.dll","libwinpthread-1.dll" }) {
740-
for (String dir : new String[]{
741-
"C:\\msys64\\mingw64\\bin","C:\\msys2\\mingw64\\bin"}) {
742-
File src = new File(dir, dll);
743-
if (src.exists()) {
744-
try { java.nio.file.Files.copy(src.toPath(),
745-
new File(binary.getParent(), dll).toPath(),
746-
java.nio.file.StandardCopyOption.REPLACE_EXISTING); }
747-
catch (Exception ignored) {}
748-
break;
749-
}
750-
}
751-
}
752-
listener.statusNotice("Libraries installed — you can now run your sketch.");
753-
javax.swing.JOptionPane.showMessageDialog(null,
754-
"GLFW and GLEW installed successfully!\nYou can now run your sketch.",
755-
"Done", javax.swing.JOptionPane.INFORMATION_MESSAGE);
756-
} else {
757-
listener.statusError("Installation failed — try manually in MSYS2 MinGW 64-bit terminal.");
758-
}
759-
} catch (Exception e) { listener.statusError("Install error: " + e.getMessage()); }
760-
}).start();
685+
// DLLs missing from bundle -- this should not happen in a correct install
686+
listener.statusError("Missing DLLs: " + String.join(", ", missing) +
687+
" -- try reinstalling CppMode from https://github.com/processing-cpp/processing.cpp");
688+
throw new Exception("Missing DLLs: " + missing);
761689
}
762690

763-
// ── macOS ──────────────────────────────────────────────────────────────────
764691
private void checkMacLibs(RunnerListener listener) throws Exception {
765692
// Check for glfw and glew via pkg-config or known Homebrew paths
766693
boolean glfwOk = new File("/opt/homebrew/lib/libglfw.dylib").exists()

0 commit comments

Comments
 (0)