Skip to content

Commit fc9baa0

Browse files
Added automatic copy of required DLLs for GitHub Actions Windows build.
1 parent ebb13e9 commit fc9baa0

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

.github/workflows/platformio-ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ jobs:
220220
cp -r .pio/build/windows/*.dll build
221221
cp -r storage build
222222
223+
- name: Copy required DLLs into artifact directory
224+
run: python scripts/github_actions/windows/get_dll.py build
225+
223226
- name: Upload artifact
224227
uses: actions/upload-artifact@v4
225228
with:
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Created by Charles Mahoudeau on 19/09/2024.
2+
3+
4+
# We could also link statically
5+
# https://stackoverflow.com/questions/18138635/mingw-exe-requires-a-few-gcc-dlls-regardless-of-the-code
6+
7+
import sys
8+
import os
9+
import shutil
10+
11+
12+
REQUIRED_DLL_LIST = [
13+
"libgcc_s_seh-1.dll",
14+
"libstdc++-6.dll",
15+
"libwinpthread-1.dll"
16+
]
17+
18+
19+
def get_compiler_bin_path():
20+
for path_value in os.environ["PATH"].split(os.pathsep):
21+
if os.path.exists(path_value + os.sep + "gcc.exe") and os.path.exists(path_value + os.sep + "g++.exe"):
22+
return path_value
23+
24+
return None
25+
26+
27+
def get_dll_paths(compiler_bin_path):
28+
paths = []
29+
30+
for dll_filename in REQUIRED_DLL_LIST:
31+
path = compiler_bin_path + os.sep + dll_filename
32+
if os.path.exists(path):
33+
paths.append(path)
34+
print("Found DLL:", dll_filename)
35+
else:
36+
print("Missing DLL:", dll_filename)
37+
38+
return paths
39+
40+
def copy_files(file_paths, destination_directory):
41+
for file_path in file_paths:
42+
shutil.copy2(file_path, destination_directory)
43+
print("Copied", file_path, "to", destination_directory)
44+
45+
46+
if __name__ == "__main__":
47+
if len(sys.argv) < 2:
48+
print("Missing target directory in arguments.")
49+
sys.exit(1)
50+
51+
target_dir = sys.argv[1]
52+
53+
if not os.path.isdir(target_dir):
54+
print("Target directory is not a directory.")
55+
sys.exit(1)
56+
57+
compiler_path = get_compiler_bin_path()
58+
59+
if compiler_path is None:
60+
print("Unable to find a compiler.")
61+
sys.exit(1)
62+
63+
print("Using compiler:", compiler_path)
64+
65+
dll_paths = get_dll_paths(compiler_path)
66+
67+
copy_files(dll_paths, target_dir)
68+
69+
print("Done.")

0 commit comments

Comments
 (0)