Skip to content

Commit 6945175

Browse files
author
Nie Zhihe
committed
feat: copy mingw runtime dlls to multiple output locations
1 parent 148ab0c commit 6945175

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

.gnfiles/build/feature/ten_package.gni

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,52 @@ template("ten_package") {
391391
}
392392
}
393393

394+
# For MinGW builds, automatically copy runtime DLLs to C++ packages
395+
# This applies to: C++ extensions, python_addon_loader, and system packages
396+
if (is_win && is_mingw && should_set_package_output_root_dir) {
397+
# Only copy DLLs for packages that build native code (not Python/Go/Node.js only packages)
398+
_should_copy_mingw_dlls = false
399+
400+
if (invoker.package_kind == "app") {
401+
# Apps always need DLLs in bin/ directory (where the executable is)
402+
if (defined(invoker.enable_build) && invoker.enable_build) {
403+
_should_copy_mingw_dlls = true
404+
}
405+
} else if (invoker.package_kind == "addon_loader") {
406+
# Addon loaders always need DLLs if they have enable_build
407+
if (defined(invoker.enable_build) && invoker.enable_build) {
408+
_should_copy_mingw_dlls = true
409+
}
410+
} else if (invoker.package_kind == "system") {
411+
# System packages always need DLLs (they package native libraries)
412+
_should_copy_mingw_dlls = true
413+
} else if (invoker.package_kind == "extension") {
414+
# For extensions, only copy if they have C++ sources and enable_build
415+
if (defined(invoker.enable_build) && invoker.enable_build &&
416+
defined(invoker.sources) && invoker.sources != []) {
417+
_should_copy_mingw_dlls = true
418+
}
419+
}
420+
421+
if (_should_copy_mingw_dlls) {
422+
import("//.gnfiles/build/toolchain/mingw/copy_runtime_dlls.gni")
423+
424+
# Default to lib/ directory, but apps use bin/
425+
_mingw_dll_output_dir = "${package_output_root_dir}/lib"
426+
if (invoker.package_kind == "app") {
427+
_mingw_dll_output_dir = "${package_output_root_dir}/bin"
428+
}
429+
430+
_copy_mingw_dlls_target = "${_target_name}_copy_mingw_dlls"
431+
copy_mingw_runtime_dlls(_copy_mingw_dlls_target) {
432+
output_dir = _mingw_dll_output_dir
433+
}
434+
435+
# Add to package_deps so it's included in the main group
436+
package_deps += [ ":${_copy_mingw_dlls_target}" ]
437+
}
438+
}
439+
394440
group(_target_name) {
395441
if (defined(public_deps)) {
396442
public_deps += package_deps

0 commit comments

Comments
 (0)