Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[meson] fix windows linker detection #22032

Merged
merged 4 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions ports/vcpkg-tool-meson/fix_linker_detection.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git a/tools/meson/mesonbuild/compilers/detect.py b/tools/meson/mesonbuild/compilers/detect.py
index 1eacecfa8..74668da1a 100644
--- a/tools/meson/mesonbuild/compilers/detect.py
+++ b/tools/meson/mesonbuild/compilers/detect.py
@@ -292,7 +292,7 @@ def detect_static_linker(env: 'Environment', compiler: Compiler) -> StaticLinker
linkers = default_linkers
popen_exceptions = {}
for linker in linkers:
- if not {'lib', 'lib.exe', 'llvm-lib', 'llvm-lib.exe', 'xilib', 'xilib.exe'}.isdisjoint(linker):
+ if any(os.path.basename(x) in {'lib', 'lib.exe', 'llvm-lib', 'llvm-lib.exe', 'xilib', 'xilib.exe'} for x in linker):
arg = '/?'
elif not {'ar2000', 'ar2000.exe'}.isdisjoint(linker):
arg = '?'
diff --git a/tools/meson/mesonbuild/linkers/detect.py b/tools/meson/mesonbuild/linkers/detect.py
index 0bfd7083b..323801d9a 100644
--- a/tools/meson/mesonbuild/linkers/detect.py
+++ b/tools/meson/mesonbuild/linkers/detect.py
@@ -72,6 +72,7 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
override = [] # type: T.List[str]
value = env.lookup_binary_entry(for_machine, comp_class.language + '_ld')
if value is not None:
+ compiler = value
override = comp_class.use_linker_args(value[0])
check_args += override

1 change: 1 addition & 0 deletions ports/vcpkg-tool-meson/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if(NOT "${program}")
z_vcpkg_apply_patches(
SOURCE_PATH "${CURRENT_PACKAGES_DIR}"
PATCHES meson-intl.patch
fix_linker_detection.patch
)
endif()

Expand Down
1 change: 1 addition & 0 deletions ports/vcpkg-tool-meson/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "vcpkg-tool-meson",
"version": "0.60.2",
"port-version": 1,
"description": "Meson build system",
"homepage": "https://github.com/mesonbuild/meson",
"supports": "native"
Expand Down
109 changes: 44 additions & 65 deletions scripts/cmake/vcpkg_configure_meson.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,45 +40,72 @@ This command supplies many common arguments to Meson. To see the full list, exam
* [libepoxy](https://github.com/Microsoft/vcpkg/blob/master/ports/libepoxy/portfile.cmake)
#]===]

function(z_vcpkg_meson_generate_native_file additional_binaries) #https://mesonbuild.com/Native-environments.html
set(native_config "[binaries]\n")
#set(proglist AR RANLIB STRIP NM OBJDUMP DLLTOOL MT)
function(z_vcpkg_append_proglist var_to_append additional_binaries)
string(APPEND "${var_to_append}" "[binaries]\n")
if(VCPKG_TARGET_IS_WINDOWS)
set(proglist MT)
set(proglist MT AR)
else()
set(proglist AR RANLIB STRIP NM OBJDUMP DLLTOOL MT)
endif()
foreach(prog IN LISTS proglist)
if(VCPKG_DETECTED_CMAKE_${prog})
string(TOLOWER "${prog}" proglower)
string(APPEND native_config "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}}'\n")
if(meson_${prog})
string(APPEND "${var_to_append}" "${meson_${prog}} = '${VCPKG_DETECTED_CMAKE_${prog}}'\n")
else()
string(TOLOWER "${prog}" proglower)
string(APPEND "${var_to_append}" "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}}'\n")
endif()
endif()
endforeach()
set(programs C CXX RC)
set(meson_RC windres)
set(meson_CXX cpp)
foreach(prog IN LISTS programs)
if(VCPKG_DETECTED_CMAKE_${prog}_COMPILER)
string(REPLACE "CXX" "CPP" mesonprog "${prog}")
string(REPLACE "RC" "windres" mesonprog "${mesonprog}") # https://mesonbuild.com/Windows-module.html
string(TOLOWER "${mesonprog}" proglower)
string(APPEND native_config "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}'\n")
if(meson_${prog})
string(APPEND "${var_to_append}" "${meson_${prog}} = '${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}'\n")
else()
string(TOLOWER "${prog}" proglower)
string(APPEND "${var_to_append}" "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}'\n")
endif()
endif()
endforeach()
if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS)
# for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456
if (NOT VCPKG_DETECTED_CMAKE_C_COMPILER_ID MATCHES "^(GNU|Intel)$")
string(APPEND native_config "c_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n")
string(APPEND "${var_to_append}" "c_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n")
endif()
endif()
if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS)
# for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456
if (NOT VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Intel)$")
string(APPEND native_config "cpp_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n")
string(APPEND "${var_to_append}" "cpp_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n")
endif()
endif()
string(APPEND native_config "cmake = '${CMAKE_COMMAND}'\n")

get_filename_component(CMAKE_PATH "${CMAKE_COMMAND}" DIRECTORY)
#vcpkg_add_to_path("${CMAKE_PATH}") # Make CMake invokeable for Meson
string(APPEND "${var_to_append}" "cmake = '${CMAKE_COMMAND}'\n")

vcpkg_find_acquire_program(PYTHON3)
get_filename_component(PYTHON3_DIR "${PYTHON3}" DIRECTORY)
vcpkg_add_to_path("${PYTHON3_DIR}")
string(APPEND "${var_to_append}" "python = '${PYTHON3}'\n")

vcpkg_find_acquire_program(NINJA)
get_filename_component(NINJA_PATH ${NINJA} DIRECTORY)
vcpkg_add_to_path(PREPEND "${NINJA_PATH}") # Prepend to use the correct ninja.
# string(APPEND "${var_to_append}" "ninja = '${NINJA}'\n") # This does not work due to meson issues

foreach(additional_binary IN LISTS additional_binaries)
string(APPEND native_config "${additional_binary}\n")
string(APPEND "${var_to_append}" "${additional_binary}\n")
endforeach()
set("${var_to_append}" "${${var_to_append}}" PARENT_SCOPE)
endfunction()

function(z_vcpkg_meson_generate_native_file additional_binaries) #https://mesonbuild.com/Native-environments.html
set(native_config "")
z_vcpkg_append_proglist(native_config "${additional_binaries}")

string(APPEND native_config "[built-in options]\n") #https://mesonbuild.com/Builtin-options.html
if(VCPKG_DETECTED_CMAKE_C_COMPILER MATCHES "cl.exe")
Expand Down Expand Up @@ -276,43 +303,9 @@ function(z_vcpkg_meson_generate_cross_file additional_binaries) #https://mesonbu
else()
message(FATAL_ERROR "Unsupported target architecture ${VCPKG_TARGET_ARCHITECTURE}!" )
endif()
set(cross_file "[binaries]\n")
if(VCPKG_TARGET_IS_WINDOWS)
set(proglist MT)
else()
set(proglist AR RANLIB STRIP NM OBJDUMP DLLTOOL MT)
endif()
foreach(prog IN LISTS proglist)
if(VCPKG_DETECTED_CMAKE_${prog})
string(TOLOWER "${prog}" proglower)
string(APPEND cross_file "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}}'\n")
endif()
endforeach()
set(programs C CXX RC)
foreach(prog IN LISTS programs)
if(VCPKG_DETECTED_CMAKE_${prog}_COMPILER)
string(REPLACE "CXX" "CPP" mesonprog "${prog}")
string(REPLACE "RC" "windres" mesonprog "${mesonprog}") # https://mesonbuild.com/Windows-module.html
string(TOLOWER "${mesonprog}" proglower)
string(APPEND cross_file "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}'\n")
endif()
endforeach()
if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS)
# for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456
if (NOT VCPKG_DETECTED_CMAKE_C_COMPILER_ID MATCHES "^(GNU|Intel)$")
string(APPEND cross_file "c_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n")
endif()
endif()
if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS)
# for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456
if (NOT VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Intel)$")
string(APPEND cross_file "cpp_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n")
endif()
endif()
string(APPEND cross_file "cmake = '${CMAKE_COMMAND}'\n")
foreach(additional_binary IN LISTS additional_binaries)
string(APPEND cross_file "${additional_binary}\n")
endforeach()

set(cross_file "")
z_vcpkg_append_proglist(cross_file "${additional_binaries}")

string(APPEND cross_file "[properties]\n")

Expand Down Expand Up @@ -391,22 +384,8 @@ function(vcpkg_configure_meson)
debug_message("Including cmake vars from: ${cmake_vars_file}")
include("${cmake_vars_file}")

vcpkg_find_acquire_program(PYTHON3)
get_filename_component(PYTHON3_DIR "${PYTHON3}" DIRECTORY)
vcpkg_add_to_path("${PYTHON3_DIR}")
vcpkg_list(APPEND arg_ADDITIONAL_NATIVE_BINARIES "python = '${PYTHON3}'")
vcpkg_list(APPEND arg_ADDITIONAL_CROSS_BINARIES "python = '${PYTHON3}'")

vcpkg_find_acquire_program(MESON)

get_filename_component(CMAKE_PATH ${CMAKE_COMMAND} DIRECTORY)
vcpkg_add_to_path("${CMAKE_PATH}") # Make CMake invokeable for Meson

vcpkg_find_acquire_program(NINJA)
get_filename_component(NINJA_PATH ${NINJA} DIRECTORY)
vcpkg_add_to_path(PREPEND "${NINJA_PATH}") # Need to prepend so that meson picks up the correct ninja from vcpkg ....
# vcpkg_list(APPEND arg_ADDITIONAL_NATIVE_BINARIES "ninja = '${NINJA}'") # This does not work due to meson issues ......

vcpkg_list(APPEND arg_OPTIONS --buildtype plain --backend ninja --wrap-mode nodownload)

if(NOT vcpkg_meson_cross_file)
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -7126,7 +7126,7 @@
},
"vcpkg-tool-meson": {
"baseline": "0.60.2",
"port-version": 0
"port-version": 1
},
"vcpkg-tool-nodejs": {
"baseline": "14.17.4",
Expand Down
5 changes: 5 additions & 0 deletions versions/v-/vcpkg-tool-meson.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "932036adfc24dd5fa63787b825974b6938402700",
"version": "0.60.2",
"port-version": 1
},
{
"git-tree": "e6ef15a9dc810b4bde53d9b1e3da3a20107e3983",
"version": "0.60.2",
Expand Down