Skip to content

Commit

Permalink
(#25015) [gobject-introspection] Migrate to Conan 2.x
Browse files Browse the repository at this point in the history
* gobject-introspection: migrate to Conan v2

* gobject-introspection: bump deps

* gobject-introspection: bump deps, transitive_headers=True

* gobject-introspection: use flexible version for glib

* gobject-introspection: fix linker error

* gobject-introspection: drop old versions, add v1.76.1

* gobject-introspection: cannot be built with shared glib

* gobject-introspection: required_conan_version = ">=1.53.0"

For rm_safe()

* gobject-introspection: add a comment for the glib version requirement

* gobject-introspection: fix build, add proper girepository test

* gobject-introspection: set correct min Conan version

* gobject-introspection: skip tests against g-ir tools when cross-compiling

* gobject-introspection: bump to v78.1

* gobject-introspection: bump deps

* gobject-introspection: disable Windows Debug builds

* gobject-introspection: update version

* Drop version 1.80.1

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Simplify test package

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Use version range for pkgconf

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Do not enforce PKG_CONFIG_PATH

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Add short_paths due Conan 1.x

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Fix missing PKG_CONFIG_PATH

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Use generators folder

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Fix res folder location

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Add fix_apple_shared_install_name

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Disable introspection_data when cross-building

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Fix Conan 1.x test package execution

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Fix test paths

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Disable introspection_data for osx

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Disable introspection_data for osx

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Enforce using static glib when building

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Enforce glib 2.76 due compatibility

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* use glib 2.78.3

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* avoid introspection data on Mac

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Add option for build_introspection_data

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* set glib to shared=True

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Add libffi as dependency

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Define GIT PATH

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Fix typo

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Fix pkg config path define

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* force glib only when using build_introspection_data

Signed-off-by: Uilian Ries <uilianries@gmail.com>

---------

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: Martin Valgur <martin.valgur@gmail.com>
  • Loading branch information
uilianries and valgur authored Sep 4, 2024
1 parent 1131ace commit 1cebce4
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 145 deletions.
17 changes: 1 addition & 16 deletions recipes/gobject-introspection/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
sources:
"1.72.0":
sha256: "02fe8e590861d88f83060dd39cda5ccaa60b2da1d21d0f95499301b186beaabc"
url: "https://download.gnome.org/sources/gobject-introspection/1.72/gobject-introspection-1.72.0.tar.xz"
"1.70.0":
url: "https://download.gnome.org/sources/gobject-introspection/1.70/gobject-introspection-1.70.0.tar.xz"
sha256: "902b4906e3102d17aa2fcb6dad1c19971c70f2a82a159ddc4a94df73a3cafc4a"
"1.69.0":
url: "https://download.gnome.org/sources/gobject-introspection/1.69/gobject-introspection-1.69.0.tar.xz"
sha256: "c668cbe4a3aad7539e2cf669ab576ce7fbadac6890472f4095ca215dbbebee99"
"1.68.0":
url: "https://download.gnome.org/sources/gobject-introspection/1.68/gobject-introspection-1.68.0.tar.xz"
sha256: "d229242481a201b84a0c66716de1752bca41db4133672cfcfb37c93eb6e54a27"
"1.67.1":
url: "https://download.gnome.org/sources/gobject-introspection/1.67/gobject-introspection-1.67.1.tar.xz"
sha256: "9635184d668794609f9fe661c5bde11c106385d26c3babe291c24e3655987e47"
"1.66.1":
url: "https://download.gnome.org/sources/gobject-introspection/1.66/gobject-introspection-1.66.1.tar.xz"
sha256: "dd44a55ee5f426ea22b6b89624708f9e8d53f5cc94e5485c15c87cb30e06161d"
sha256: "02fe8e590861d88f83060dd39cda5ccaa60b2da1d21d0f95499301b186beaabc"
253 changes: 156 additions & 97 deletions recipes/gobject-introspection/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,129 +1,188 @@
from conans import ConanFile, tools, Meson, VisualStudioBuildEnvironment
from conans.errors import ConanInvalidConfiguration
import os
import shutil
import glob

required_conan_version = ">=1.36.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import cross_building
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
from conan.tools.files import copy, get, replace_in_file, rm, rmdir
from conan.tools.gnu import PkgConfigDeps
from conan.tools.layout import basic_layout
from conan.tools.meson import MesonToolchain, Meson
from conan.tools.env import Environment
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.scm import Version
from conan import conan_version

required_conan_version = ">=1.60.0 <2.0 || >=2.0.5"


class GobjectIntrospectionConan(ConanFile):
name = "gobject-introspection"
description = "GObject introspection is a middleware layer between C libraries (using GObject) and language bindings"
topics = ("conan", "gobject-instrospection")
description = ("GObject introspection is a middleware layer between "
"C libraries (using GObject) and language bindings")
license = "LGPL-2.1-or-later"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://gitlab.gnome.org/GNOME/gobject-introspection"
license = "LGPL-2.1"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
generators = "pkg_config"
topics = ("gobject-instrospection",)

@property
def _is_msvc(self):
return self.settings.compiler == "Visual Studio"

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
package_type = "shared-library"
settings = "os", "arch", "compiler", "build_type"
options = {
"fPIC": [True, False],
"build_introspection_data": [True, False],
}
default_options = {
"fPIC": True,
"build_introspection_data": True,
}
short_paths = True

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if self.settings.os == "Windows":
raise ConanInvalidConfiguration("%s recipe does not support windows. Contributions are welcome!" % self.name)
if self.settings.os in ["Windows", "Macos"] or cross_building(self):
# FIXME: tools/g-ir-scanner fails to load glib
self.options.build_introspection_data = False

def configure(self):
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")
if self.options.get_safe("build_introspection_data"):
# INFO: g-ir-scanner looks for dynamic glib and gobject libraries when running
self.options["glib"].shared = True

def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
# https://gitlab.gnome.org/GNOME/gobject-introspection/-/blob/1.76.1/meson.build?ref_type=tags#L127-131
self.requires("glib/2.78.3", transitive_headers=True, transitive_libs=True)
# ffi.h is exposed by public header gobject-introspection-1.0/girffi.h
self.requires("libffi/3.4.4", transitive_headers=True)

def validate(self):
if self.settings.os == "Windows" and self.settings.build_type == "Debug":
# fatal error LNK1104: cannot open file 'python37_d.lib'
raise ConanInvalidConfiguration(
f"{self.ref} debug build on Windows is disabled due to debug version of Python libs likely not being available. Contributions to fix this are welcome.")
if self.options.build_introspection_data and not self.dependencies["glib"].options.shared:
# FIXME: tools/g-ir-scanner fails to load glib
# tools/g-ir-scanner --output=gir/GLib-2.0.gir ...
# ERROR: can't resolve libraries to shared libraries: glib-2.0, gobject-2.0
raise ConanInvalidConfiguration(f"{self.ref} requires shared glib to be built as shared. Use -o 'glib/*:shared=True'.")
if self.options.build_introspection_data and self.settings.os in ["Windows", "Macos"]:
# FIXME: tools/g-ir-scanner', '--output=gir/GLib-2.0.gir' ... ERROR: can't resolve libraries to shared libraries: glib-2.0, gobject-2.0
# FIXME: g-ir-scanner fails to find libgnuintl
# giscanner/_giscanner.cpython-37m-darwin.so, 0x0002): Library not loaded: /lib/libgnuintl.8.dylib
raise ConanInvalidConfiguration(f"{self.ref} fails to run g-ir-scanner due glib loaded as shared. Use -o 'glib/*:shared=False'. Contributions to fix this are welcome.")
if self.options.build_introspection_data and cross_building(self):
raise ConanInvalidConfiguration(f"{self.ref} build_introspection_data is not supported when cross-building. Use '&:build_introspection_data=False'.")

def build_requirements(self):
if tools.Version(self.version) >= "1.71.0":
self.build_requires("meson/0.62.2")
else:
# https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/414
self.build_requires("meson/0.59.3")
self.build_requires("pkgconf/1.7.4")
self.tool_requires("meson/[>=1.2.3 <2]")
if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
self.tool_requires("pkgconf/[>=2.2 <3]")
if self.settings.os == "Windows":
self.build_requires("winflexbison/2.5.24")
self.tool_requires("winflexbison/2.5.25")
else:
self.build_requires("flex/2.6.4")
self.build_requires("bison/3.7.6")

def requirements(self):
self.requires("glib/2.73.0")
self.tool_requires("flex/2.6.4")
self.tool_requires("bison/3.8.2")
self.tool_requires("glib/<host_version>")

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)

def _configure_meson(self):
meson = Meson(self)
defs = dict()
defs["build_introspection_data"] = self.options["glib"].shared
defs["datadir"] = os.path.join(self.package_folder, "res")

meson.configure(
source_folder=self._source_subfolder,
args=["--wrap-mode=nofallback"],
build_folder=self._build_subfolder,
defs=defs,
)
return meson
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
env = VirtualBuildEnv(self)
env.generate()
if not cross_building(self):
env = VirtualRunEnv(self)
env.generate(scope="build")
tc = MesonToolchain(self)
if cross_building(self):
tc.project_options["gi_cross_use_prebuilt_gi"] = "false"
tc.project_options["build_introspection_data"] = self.options.build_introspection_data
tc.project_options["datadir"] = "res"
tc.generate()
deps = PkgConfigDeps(self)
deps.generate()
# INFO: g-ir-scanner uses PKG_CONFIG_PATH directly instead of pkg-config Meson module
env = Environment()
env.define_path("PKG_CONFIG_PATH", self.generators_folder)
envvars = env.vars(self)
envvars.save_script("pkg_config_env")

def _patch_sources(self):
# Disable tests
replace_in_file(self, os.path.join(self.source_folder, "meson.build"),
"subdir('tests')",
"#subdir('tests')")
# Look for data files in res/ instead of share/
replace_in_file(self, os.path.join(self.source_folder, "tools", "g-ir-tool-template.in"),
"os.path.join(filedir, '..', 'share')",
"os.path.join(filedir, '..', 'res')")
if Version(conan_version) < "2":
# INFO: Conan 1.x generates PkgConfigDeps with libdir1 and includedir1 variables only for glib due its modules
replace_in_file(self, os.path.join(self.source_folder, "gir", "meson.build"),
"glib_dep.get_variable(pkgconfig: 'libdir')",
"glib_dep.get_variable(pkgconfig: 'libdir1')")
replace_in_file(self, os.path.join(self.source_folder, "gir", "meson.build"),
"join_paths(glib_dep.get_variable(pkgconfig: 'includedir'), 'glib-2.0')",
"join_paths(glib_dep.get_variable(pkgconfig: 'includedir1'), 'glib-2.0')")
# gir/meson.build expects the gio-unix-2.0 includedir to be passed as a build flag.
# Patch this for glib from Conan.
replace_in_file(self, os.path.join(self.source_folder, "gir", "meson.build"),
"join_paths(giounix_dep.get_variable(pkgconfig: 'includedir'), 'gio-unix-2.0')",
"giounix_dep.get_variable(pkgconfig: 'includedir1')")
else:
# gir/meson.build expects the gio-unix-2.0 includedir to be passed as a build flag.
# Patch this for glib from Conan.
replace_in_file(self, os.path.join(self.source_folder, "gir", "meson.build"),
"join_paths(giounix_dep.get_variable(pkgconfig: 'includedir'), 'gio-unix-2.0')",
"giounix_dep.get_variable(pkgconfig: 'includedir')")

def build(self):
tools.replace_in_file(
os.path.join(self._source_subfolder, "meson.build"),
"subdir('tests')",
"#subdir('tests')",
)
tools.replace_in_file(
os.path.join(self._source_subfolder, "meson.build"),
"if meson.version().version_compare('>=0.54.0')",
"if false",
)

with tools.environment_append(
VisualStudioBuildEnvironment(self).vars
if self._is_msvc
else {"PKG_CONFIG_PATH": self.build_folder}
):
meson = self._configure_meson()
meson.build()
self._patch_sources()
meson = Meson(self)
meson.configure()
meson.build()

def package(self):
self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder)
with tools.environment_append(
VisualStudioBuildEnvironment(self).vars
) if self._is_msvc else tools.no_op():
meson = self._configure_meson()
meson.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))
for pdb_file in glob.glob(os.path.join(self.package_folder, "bin", "*.pdb")):
os.unlink(pdb_file)
copy(self, "COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
meson = Meson(self)
meson.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.pdb", self.package_folder, recursive=True)
fix_apple_shared_install_name(self)

def package_info(self):
self.cpp_info.names["pkg_config"] = "gobject-introspection-1.0"
self.cpp_info.set_property("pkg_config_name", "gobject-introspection-1.0")
self.cpp_info.libs = ["girepository-1.0"]
self.cpp_info.includedirs.append(
os.path.join("include", "gobject-introspection-1.0")
)

bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH env var with: {}".format(bin_path))
self.env_info.PATH.append(bin_path)
self.cpp_info.includedirs.append(os.path.join("include", "gobject-introspection-1.0"))

exe_ext = ".exe" if self.settings.os == "Windows" else ""

pkgconfig_variables = {
'datadir': '${prefix}/res',
'bindir': '${prefix}/bin',
'g_ir_scanner': '${bindir}/g-ir-scanner',
'g_ir_compiler': '${bindir}/g-ir-compiler%s' % exe_ext,
'g_ir_generate': '${bindir}/g-ir-generate%s' % exe_ext,
'gidatadir': '${datadir}/gobject-introspection-1.0',
'girdir': '${datadir}/gir-1.0',
'typelibdir': '${libdir}/girepository-1.0',
"datadir": "${prefix}/res",
"bindir": "${prefix}/bin",
"libdir": "${prefix}/lib",
"g_ir_scanner": "${bindir}/g-ir-scanner",
"g_ir_compiler": "${bindir}/g-ir-compiler%s" % exe_ext,
"g_ir_generate": "${bindir}/g-ir-generate%s" % exe_ext,
"gidatadir": "${datadir}/gobject-introspection-1.0",
"girdir": "${datadir}/gir-1.0",
"typelibdir": "${libdir}/girepository-1.0",
}
self.cpp_info.set_property(
"pkg_config_custom_content",
"\n".join("%s=%s" % (key, value) for key,value in pkgconfig_variables.items()))
"\n".join(f"{key}={value}" for key, value in pkgconfig_variables.items()),
)
self.buildenv_info.define_path("GI_GIR_PATH", os.path.join(self.package_folder, "res", "gir-1.0"))
self.buildenv_info.define_path("GI_TYPELIB_PATH", os.path.join(self.package_folder, "lib", "girepository-1.0"))

# TODO: remove in conan v2
bin_path = os.path.join(self.package_folder, "bin")
self.env_info.PATH.append(bin_path)
self.env_info.GI_GIR_PATH = os.path.join(self.package_folder, "res", "gir-1.0")
self.env_info.GI_TYPELIB_PATH = os.path.join(self.package_folder, "lib", "girepository-1.0")
14 changes: 9 additions & 5 deletions recipes/gobject-introspection/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(gobject-introspection REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
add_executable(test_basic test_basic.c)
target_link_libraries(test_basic PRIVATE gobject-introspection::gobject-introspection)

if(GLIB_INTROSPECTION_DATA_AVAILABLE)
add_executable(test_girepository test_girepository.c)
target_link_libraries(test_girepository PRIVATE gobject-introspection::gobject-introspection)
endif()
59 changes: 45 additions & 14 deletions recipes/gobject-introspection/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,57 @@
from conans import ConanFile, CMake, tools
import os

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain
from conan.tools.files import save, load
from conan.tools.apple import is_apple_os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package", "pkg_config"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def build(self):
if self.settings.os != 'Windows':
with tools.environment_append({'PKG_CONFIG_PATH': "."}):
pkg_config = tools.PkgConfig("gobject-introspection-1.0")
for tool in ["g_ir_compiler", "g_ir_generate", "g_ir_scanner"]:
self.run('%s --version' % pkg_config.variables[tool], run_environment=True)
self.run('g-ir-annotation-tool --version', run_environment=True)
self.run('g-ir-inspect -h', run_environment=True)
def requirements(self):
self.requires(self.tested_reference_str, run=True)

def layout(self):
cmake_layout(self)

def generate(self):
introspection_data = self.dependencies["glib"].options.shared and not is_apple_os(self)
tc = CMakeToolchain(self)
tc.variables["GLIB_INTROSPECTION_DATA_AVAILABLE"] = introspection_data
tc.generate()
save(self, os.path.join(self.build_folder, "gobject_introspection_data"), str(introspection_data))
save(self, os.path.join(self.build_folder, "gobject_introspection_bin"),
self.dependencies["gobject-introspection"].cpp_info.bindirs[0])

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
if self.settings.os != "Windows":
gobject_introspection_bin = load(self, os.path.join(self.build_folder, "gobject_introspection_bin"))
gobject_introspection_data = load(self, os.path.join(self.build_folder, "gobject_introspection_data")) == "True"
for tool in ["g-ir-compiler", "g-ir-generate", "g-ir-scanner", "g-ir-annotation-tool"]:
if not gobject_introspection_data and tool in ["g-ir-scanner", "g-ir-annotation-tool"]:
continue
tool_path = os.path.join(gobject_introspection_bin, tool)
if os.path.exists(tool_path):
self.run(f"{tool_path} --version", env="conanrun")
else:
raise Exception(f"Tool {tool} not found in {gobject_introspection_bin}")
tool_path = os.path.join(gobject_introspection_bin, "g-ir-inspect")
if os.path.exists(tool_path):
self.run(f"{tool_path} -h", env="conanrun")

bin_path = os.path.join(self.cpp.build.bindir, "test_basic")
self.run(bin_path, env="conanrun")

bin_path = os.path.join(self.cpp.build.bindir, "test_girepository")
if os.path.exists(bin_path):
self.run(bin_path, env="conanrun")
Loading

0 comments on commit 1cebce4

Please sign in to comment.