From dd5dd6d1e10fd2dc793f8a9f0d4c95d4ff88c08f Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Tue, 19 Jul 2022 09:22:47 +0200 Subject: [PATCH 1/4] Disable rpath handling on Windows While gcc on Windows allows being passed -rpath and just ignores it, llvm/lld will fail with "lld: error: unknown argument: -rpath". There is no such thing as rpath on Windows, so just skip it. --- giscanner/ccompiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/giscanner/ccompiler.py b/giscanner/ccompiler.py index a6be9ee66..7a1e93938 100644 --- a/giscanner/ccompiler.py +++ b/giscanner/ccompiler.py @@ -208,7 +208,7 @@ class CCompiler(object): args.append('-libpath:' + library_path) else: args.append('-L' + library_path) - if os.path.isabs(library_path): + if os.name != 'nt' and os.path.isabs(library_path): if libtool: args.append('-rpath') args.append(library_path) -- GitLab From a3fa882fc9ddce54c51a75f4625b2a3a4170a7a0 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Tue, 19 Jul 2022 09:23:00 +0200 Subject: [PATCH 2/4] resolve_windows_libs: add llvm/mingw support The existing code tries to mirror how the linker finds DLLs by searching for the import libs and then looking for the matching shared lib name. While llvm has a dlltool clone it doesn't provide the --identify option to extract the shared lib name. Instead we use the fact that llvm import libs include the dll name in the archive member name, so we can use "nm" there to get the same result. To decide which strategy to use we run dlltool and check if it contains "llvm-dlltool" in the output. This fixes the .gir and .typelib files containing bogus values for the shared library names when building with clang + mingw-w64 on Windows. I'm not quite sure if the libtool part is actually needed there, but I left it in to keep the diff small. --- giscanner/ccompiler.py | 48 +++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/giscanner/ccompiler.py b/giscanner/ccompiler.py index 7a1e93938..2912fe0e0 100644 --- a/giscanner/ccompiler.py +++ b/giscanner/ccompiler.py @@ -95,6 +95,41 @@ def customize_compiler(compiler): compiler.shared_lib_extension = shlib_suffix +def resolve_mingw_lib(implib, libtool=None): + """Returns a DLL name given a path to an import lib + + /full/path/to/libgtk-3.dll.a -> libgtk-3-0.dll + """ + + args = [] + if libtool: + args.extend(libtool) + args.append('--mode=execute') + + # Figure out if we have a gcc toolchain or llvm one + dlltool = os.environ.get('DLLTOOL', 'dlltool.exe') + dlltool_output = subprocess.run( + [dlltool], stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + universal_newlines=True).stdout + is_llvm = 'llvm-dlltool' in dlltool_output + + if not is_llvm: + # gcc dlltool provides this via --identify + dlltool_args = args + [dlltool, '--identify'] + output = subprocess.check_output(dlltool_args + [implib], universal_newlines=True) + for line in output.splitlines(): + return line + else: + # for llvm we need to parse the output of nm + # https://github.com/msys2/MINGW-packages/issues/11994#issuecomment-1176691216 + output = subprocess.check_output(args + ['nm', implib], universal_newlines=True) + for line in output.splitlines(): + if line.endswith(':'): + return line[:-1] + return None + + # Flags that retain macros in preprocessed output. FLAGS_RETAINING_MACROS = ['-g3', '-ggdb3', '-gstabs3', '-gcoff3', '-gxcoff3', '-gvms3'] @@ -341,10 +376,6 @@ class CCompiler(object): # When we are not using Visual C++ nor clang-cl (i.e. we are using GCC)... else: libtool = utils.get_libtool_command(options) - if libtool: - args.extend(libtool) - args.append('--mode=execute') - args.extend([os.environ.get('DLLTOOL', 'dlltool.exe'), '--identify']) proc = subprocess.Popen([self.compiler_cmd, '-print-search-dirs'], stdout=subprocess.PIPE) o, e = proc.communicate() @@ -400,13 +431,10 @@ class CCompiler(object): tmp_fileobj.close() os.unlink(tmp_filename) else: - proc = subprocess.Popen(args + [implib], - stdout=subprocess.PIPE) - o, e = proc.communicate() - for line in o.decode('ascii').splitlines(): - shlibs.append(line) + shlib = resolve_mingw_lib(implib, libtool) + if shlib is not None: + shlibs.append(shlib) found = True - break if not found: not_resolved.append(lib) if len(not_resolved) > 0: -- GitLab From ebd0f1282846ab1e325b7c9b4161b4d1cc5fa54c Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Tue, 19 Jul 2022 18:03:59 +0200 Subject: [PATCH 3/4] build: disable some clang warnings for code not under our control cmph is vendored and other one is bison/flex generated code. Not much we can do here, so disable those warnings there. --- girepository/cmph/meson.build | 1 + giscanner/meson.build | 1 + 2 files changed, 2 insertions(+) diff --git a/girepository/cmph/meson.build b/girepository/cmph/meson.build index 2a0cef7e4..157b09e96 100644 --- a/girepository/cmph/meson.build +++ b/girepository/cmph/meson.build @@ -43,6 +43,7 @@ if cc.get_id() != 'msvc' '-Wno-cast-align', '-Wno-unused-function', '-Wno-return-type', + '-Wno-sometimes-uninitialized', ]) endif diff --git a/giscanner/meson.build b/giscanner/meson.build index 3d7dc678a..5cb6036b0 100644 --- a/giscanner/meson.build +++ b/giscanner/meson.build @@ -83,6 +83,7 @@ if cc.get_id() != 'msvc' custom_c_args = cc.get_supported_arguments([ '-Wno-missing-field-initializers', '-Wno-unused-parameter', + '-Wno-misleading-indentation', ]) endif -- GitLab From d81b95acf89e09bb96504aa865957f9c1a4c5881 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sat, 16 Jul 2022 20:43:39 +0200 Subject: [PATCH 4/4] CI: test with clang + mingw-w64 on Windows The toolchain is different enough to warrant its own CI job imo. --- .gitlab-ci.yml | 16 ++++++++++++++++ .gitlab-ci/test-msys2-meson.sh | 32 +++++++++++++------------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 18c9c7beb..85f622d33 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -143,6 +143,22 @@ msys2-mingw64-meson: paths: - _build/meson-logs +msys2-clang64-meson: + stage: build + tags: + - win32-ps + variables: + MSYSTEM: "CLANG64" + CHERE_INVOKING: "yes" + script: + - C:\msys64\usr\bin\pacman --noconfirm -Syyuu + - C:\msys64\usr\bin\bash -lc "bash -x ./.gitlab-ci/test-msys2-meson.sh" + artifacts: + when: on_failure + name: "gi-_${env:CI_COMMIT_REF_NAME}" + paths: + - _build/meson-logs + vs2017-x64-meson: stage: build tags: diff --git a/.gitlab-ci/test-msys2-meson.sh b/.gitlab-ci/test-msys2-meson.sh index c61efcdea..2fe3d6e0d 100644 --- a/.gitlab-ci/test-msys2-meson.sh +++ b/.gitlab-ci/test-msys2-meson.sh @@ -2,30 +2,24 @@ set -e -if [[ "$MSYSTEM" == "MINGW32" ]]; then - export MSYS2_ARCH="i686" -else - export MSYS2_ARCH="x86_64" -fi - pacman --noconfirm -Suy pacman --noconfirm -S --needed \ git \ base-devel \ - mingw-w64-$MSYS2_ARCH-toolchain \ - mingw-w64-$MSYS2_ARCH-ccache \ - mingw-w64-$MSYS2_ARCH-meson \ - mingw-w64-$MSYS2_ARCH-python3 \ - mingw-w64-$MSYS2_ARCH-python3-pip \ - mingw-w64-$MSYS2_ARCH-python3-mako \ - mingw-w64-$MSYS2_ARCH-python3-markdown \ - mingw-w64-$MSYS2_ARCH-libffi \ - mingw-w64-$MSYS2_ARCH-pkg-config \ - mingw-w64-$MSYS2_ARCH-cairo \ - mingw-w64-$MSYS2_ARCH-pcre2 \ - mingw-w64-$MSYS2_ARCH-zlib \ - mingw-w64-$MSYS2_ARCH-gettext + ${MINGW_PACKAGE_PREFIX}-toolchain \ + ${MINGW_PACKAGE_PREFIX}-ccache \ + ${MINGW_PACKAGE_PREFIX}-meson \ + ${MINGW_PACKAGE_PREFIX}-python3 \ + ${MINGW_PACKAGE_PREFIX}-python3-pip \ + ${MINGW_PACKAGE_PREFIX}-python3-mako \ + ${MINGW_PACKAGE_PREFIX}-python3-markdown \ + ${MINGW_PACKAGE_PREFIX}-libffi \ + ${MINGW_PACKAGE_PREFIX}-pkg-config \ + ${MINGW_PACKAGE_PREFIX}-cairo \ + ${MINGW_PACKAGE_PREFIX}-pcre2 \ + ${MINGW_PACKAGE_PREFIX}-zlib \ + ${MINGW_PACKAGE_PREFIX}-gettext export CCACHE_BASEDIR="${CI_PROJECT_DIR}" export CCACHE_DIR="${CCACHE_BASEDIR}/_ccache" -- GitLab