From 06840411a8e773cff41bf865c6df9b802919680c Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 1 Oct 2019 22:51:47 +0200 Subject: [PATCH 1/7] Add swig/4.0.1 recipe --- recipes/swig/all/conandata.yml | 10 ++ recipes/swig/all/conanfile.py | 124 ++++++++++++++++++ .../0001-swig-linux-library-path.patch | 43 ++++++ ...0002-do-not-define-SWIG_LIB_WIN_UNIX.patch | 11 ++ recipes/swig/all/test_package/CMakeLists.txt | 16 +++ recipes/swig/all/test_package/conanfile.py | 31 +++++ recipes/swig/all/test_package/test.i | 7 + recipes/swig/all/test_package/test_package.c | 30 +++++ recipes/swig/config.yml | 3 + 9 files changed, 275 insertions(+) create mode 100644 recipes/swig/all/conandata.yml create mode 100644 recipes/swig/all/conanfile.py create mode 100644 recipes/swig/all/patches/0001-swig-linux-library-path.patch create mode 100644 recipes/swig/all/patches/0002-do-not-define-SWIG_LIB_WIN_UNIX.patch create mode 100644 recipes/swig/all/test_package/CMakeLists.txt create mode 100644 recipes/swig/all/test_package/conanfile.py create mode 100644 recipes/swig/all/test_package/test.i create mode 100644 recipes/swig/all/test_package/test_package.c create mode 100644 recipes/swig/config.yml diff --git a/recipes/swig/all/conandata.yml b/recipes/swig/all/conandata.yml new file mode 100644 index 0000000000000..37ca33b65eb28 --- /dev/null +++ b/recipes/swig/all/conandata.yml @@ -0,0 +1,10 @@ +sources: + "4.0.1": + url: "https://github.com/swig/swig/archive/rel-4.0.1.tar.gz" + sha256: "2eaf6fb89d071d1be280bf995c63360b3729860c0da64948123b5d7e4cfb6cb7" +patches: + "4.0.1": + - base_path: "source_subfolder" + patch_file: "patches/0001-swig-linux-library-path.patch" + - base_path: "source_subfolder" + patch_file: "patches/0002-do-not-define-SWIG_LIB_WIN_UNIX.patch" diff --git a/recipes/swig/all/conanfile.py b/recipes/swig/all/conanfile.py new file mode 100644 index 0000000000000..7d7d4e83ceeb8 --- /dev/null +++ b/recipes/swig/all/conanfile.py @@ -0,0 +1,124 @@ +from conans import ConanFile, tools, AutoToolsBuildEnvironment +from contextlib import contextmanager +import os + + +class SwigConan(ConanFile): + name = "swig" + description = "SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages." + url = "https://github.com/conan-io/conan-center-index" + homepage = "http://www.swig.org" + license = "GPL-3.0-or-later" + topics = ("conan", "swig", "python", "java", "wrapper") + exports_sources = "patches/**" + settings = "os", "arch", "compiler" + + _autotools = None + + @property + def _source_subfolder(self): + return "source_subfolder" + + def configure(self): + del self.settings.compiler.libcxx + del self.settings.compiler.cppstd + + def build_requirements(self): + if tools.os_info.is_windows and not tools.get_env("CONAN_BASH_PATH") \ + and not tools.os_info.detect_windows_subsystem() != "msys2": + self.build_requires("msys2/20190524") + if self.settings.compiler == "Visual Studio": + self.build_requires("cccl/1.1") + if tools.os_info.is_windows: + self.build_requires("winflexbison/2.5.18@bincrafters/stable") + else: + self.build_requires("bison/3.5.3") + self.build_requires("automake/1.16.2") + + def requirements(self): + self.requires("pcre/8.41") + + def source(self): + tools.get(**self.conan_data["sources"][self.version]) + os.rename("swig-rel-{}".format(self.version), self._source_subfolder) + + @contextmanager + def _build_context(self): + extra_env = { + "CONAN_CPU_COUNT": "1" if self.settings.compiler == "Visual Studio" else str(tools.cpu_count()), + } + with tools.environment_append(extra_env): + if self.settings.compiler == "Visual Studio": + with tools.vcvars(self.settings): + yield + else: + yield + + def _configure_autotools(self): + if self._autotools: + return self._autotools + + self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) + + deps_libpaths = self._autotools.library_paths + deps_libs = self._autotools.libs + deps_defines = self._autotools.defines + if self.settings.os == "Windows" and self.settings.compiler != "Visual Studio": + self._autotools.link_flags.append("-static") + + libargs = list("-L\"{}\"".format(p) for p in deps_libpaths) + list("-l\"{}\"".format(l) for l in deps_libs) + args = [ + "PCRE_LIBS={}".format(" ".join(libargs)), + "PCRE_CPPFLAGS={}".format(" ".join("-D{}".format(define) for define in deps_defines)), + "--host={}".format(self.settings.arch), + "--with-swiglibdir={}".format(self._swiglibdir), + ] + if self.settings.compiler == "Visual Studio": + self.output.warn("Visual Studio compiler cannot create ccache-swig. Disabling ccache-swig.") + args.append("--disable-ccache") + + self._autotools.configure(args=args, configure_dir=self._source_subfolder) + return self._autotools + + def _patch_sources(self): + for patch in self.conan_data["patches"][self.version]: + tools.patch(**patch) + + def build(self): + self._patch_sources() + with tools.chdir(os.path.join(self._source_subfolder)): + self.run("./autogen.sh", win_bash=tools.os_info.is_windows) + with self._build_context(): + autotools = self._configure_autotools() + autotools.make() + + def package(self): + self.copy(pattern="LICENSE*", dst="licenses", src=self._source_subfolder) + self.copy(pattern="COPYRIGHT", dst="licenses", src=self._source_subfolder) + with self._build_context(): + autotools = self._configure_autotools() + autotools.install() + + if self.settings.compiler != "Visual Studio": + with tools.chdir(os.path.join(self.package_folder, "bin")): + strip = tools.get_env("STRIP") or tools.which("strip") + ext = ".exe" if tools.os_info.is_windows else "" + if strip: + self.run("{} swig{}".format(strip, ext), win_bash=tools.os_info.is_windows) + self.run("{} ccache-swig{}".format(strip, ext), win_bash=tools.os_info.is_windows) + + def package_id(self): + del self.info.settings.compiler + + @property + def _swiglibdir(self): + return os.path.join(self.package_folder, "bin", "swiglib").replace("\\", "/") + + def package_info(self): + # FIXME: Don't set cmake_find_package name because conan cmake generators do not define SWIG_EXECUTABLE + # self.cpp_info.names["cmake_find_package"] = "SWIG" + # self.cpp_info.names["cmake_find_package_multi"] = "SWIG" + + bindir = os.path.join(self.package_folder, "bin") + self.output.info("Appending PATH environment variable: {}".format(bindir)) + self.env_info.PATH.append(bindir) diff --git a/recipes/swig/all/patches/0001-swig-linux-library-path.patch b/recipes/swig/all/patches/0001-swig-linux-library-path.patch new file mode 100644 index 0000000000000..b1f23c8961891 --- /dev/null +++ b/recipes/swig/all/patches/0001-swig-linux-library-path.patch @@ -0,0 +1,43 @@ +--- Source/Modules/main.cxx ++++ Source/Modules/main.cxx +@@ -879,6 +879,23 @@ + } + } + ++#if defined(HAVE_UNISTD_H) ++#include ++#include ++ ++static String *get_exe_path(void) { ++ char buffer[PATH_MAX]; ++ ssize_t nb = readlink("/proc/self/exe", buffer, PATH_MAX); ++ if (nb != -1) { ++ buffer[nb] = '\0'; ++ dirname(buffer); ++ strcat(buffer, "/swiglib"); ++ return NewStringWithSize(buffer, strlen(buffer)); ++ } ++ return NewString(SWIG_LIB); ++} ++#endif ++ + int SWIG_main(int argc, char *argv[], const TargetLanguageModule *tlm) { + char *c; + +@@ -938,13 +953,15 @@ + char buf[MAX_PATH]; + char *p; + if (!(GetModuleFileName(0, buf, MAX_PATH) == 0 || (p = strrchr(buf, '\\')) == 0)) { + *(p + 1) = '\0'; +- SwigLib = NewStringf("%sLib", buf); // Native windows installation path ++ SwigLib = NewStringf("%sswiglib", buf); // Native windows installation path + } else { + SwigLib = NewStringf(""); // Unexpected error + } + if (Len(SWIG_LIB_WIN_UNIX) > 0) + SwigLibWinUnix = NewString(SWIG_LIB_WIN_UNIX); // Unix installation path using a drive letter (for msys/mingw) ++#elif defined(HAVE_UNISTD_H) ++ SwigLib = get_exe_path(); + #else + SwigLib = NewString(SWIG_LIB); + #endif diff --git a/recipes/swig/all/patches/0002-do-not-define-SWIG_LIB_WIN_UNIX.patch b/recipes/swig/all/patches/0002-do-not-define-SWIG_LIB_WIN_UNIX.patch new file mode 100644 index 0000000000000..53d129b5c5349 --- /dev/null +++ b/recipes/swig/all/patches/0002-do-not-define-SWIG_LIB_WIN_UNIX.patch @@ -0,0 +1,11 @@ +--- configure.ac ++++ configure.ac +@@ -2728,7 +2728,7 @@ + *-*-cygwin*) SWIG_LIB_WIN_UNIX=`cygpath --mixed "$SWIG_LIB"`;; + *) SWIG_LIB_WIN_UNIX="";; + esac +-AC_DEFINE_UNQUOTED(SWIG_LIB_WIN_UNIX, ["$SWIG_LIB_WIN_UNIX"], [Directory for SWIG system-independent libraries (Unix install on native Windows)]) ++AC_DEFINE_UNQUOTED(SWIG_LIB_WIN_UNIX, [""], [Directory for SWIG system-independent libraries (Unix install on native Windows)]) + + SWIG_LIB_PREINST=$ABS_SRCDIR/Lib + AC_SUBST(SWIG_LIB_PREINST) diff --git a/recipes/swig/all/test_package/CMakeLists.txt b/recipes/swig/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..35522aecc0514 --- /dev/null +++ b/recipes/swig/all/test_package/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 2.8.12) +project(PackageTest C) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +find_package(SWIG REQUIRED) +include(UseSWIG) + +swig_add_library(${PROJECT_NAME} + TYPE MODULE + LANGUAGE python + SOURCES + test.i + test_package.c +) diff --git a/recipes/swig/all/test_package/conanfile.py b/recipes/swig/all/test_package/conanfile.py new file mode 100644 index 0000000000000..9f859404acc5a --- /dev/null +++ b/recipes/swig/all/test_package/conanfile.py @@ -0,0 +1,31 @@ +from conans import CMake, ConanFile, tools +from conans.errors import ConanException +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + # # FIXME: cpython is not available on CCI (yet) + # def build(self): + # cmake = CMake(self) + # cmake.configure(args=["--trace", "--trace-expand"]) + # cmake.build() + # + # def build_requirements(self): + # self.build_requires("cpython/3.8.3") + # + # def requirements(self): + # self.requires("cpython/3.8.3") + + def test(self): + if not tools.cross_building(self.settings): + # # FIXME: cpython is not available on CCI (yet) + # with tools.chdir("lib"): + # self.run("python -c \"import sys; import _PackageTest; gcd = _PackageTest.gcd(12, 16); print('gcd =', gcd); sys.exit(0 if gcd == 4 else 1)\"", run_environment=True) + # self.run("python -c \"import sys; import _PackageTest; foo = _PackageTest.cvar.foo; print('foo =', foo); sys.exit(0 if foo == 3.14159265359 else 1)\"", run_environment=True) + testdir = os.path.dirname(os.path.realpath(__file__)) + self.run("swig -python -outcurrentdir %s" % os.path.join(testdir, "test.i")) + if not os.path.isfile("example.py"): + raise ConanException("example.py is not created by swig") diff --git a/recipes/swig/all/test_package/test.i b/recipes/swig/all/test_package/test.i new file mode 100644 index 0000000000000..e2b5d581b51b3 --- /dev/null +++ b/recipes/swig/all/test_package/test.i @@ -0,0 +1,7 @@ +/* File : example.i */ +%module example + +%inline %{ +extern int gcd(int u, int v); +extern double foo; +%} diff --git a/recipes/swig/all/test_package/test_package.c b/recipes/swig/all/test_package/test_package.c new file mode 100644 index 0000000000000..f0d871a6d5ab9 --- /dev/null +++ b/recipes/swig/all/test_package/test_package.c @@ -0,0 +1,30 @@ +// Source: https://en.wikipedia.org/wiki/Binary_GCD_algorithm#Recursive_version_in_C +int gcd(int u, int v) { + // simple cases (termination) + if (u == v) + return u; + + if (u == 0) + return v; + + if (v == 0) + return u; + + // look for factors of 2 + if (~u & 1) // u is even + if (v & 1) // v is odd + return gcd(u >> 1, v); + else // both u and v are even + return gcd(u >> 1, v >> 1) << 1; + + if (~v & 1) // u is odd, v is even + return gcd(u, v >> 1); + + // reduce larger argument + if (u > v) + return gcd((u - v) >> 1, v); + + return gcd((v - u) >> 1, u); +} + +double foo = 3.14159265359; diff --git a/recipes/swig/config.yml b/recipes/swig/config.yml new file mode 100644 index 0000000000000..50b6906e5e757 --- /dev/null +++ b/recipes/swig/config.yml @@ -0,0 +1,3 @@ +versions: + "4.0.1": + folder: "all" From e34d0b160efdb159b18f82a716560194ef00a8dc Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Sat, 23 May 2020 18:23:25 +0200 Subject: [PATCH 2/7] swig: winflexbison is available on cci --- recipes/swig/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/swig/all/conanfile.py b/recipes/swig/all/conanfile.py index 7d7d4e83ceeb8..18ecbbc5323f0 100644 --- a/recipes/swig/all/conanfile.py +++ b/recipes/swig/all/conanfile.py @@ -30,7 +30,7 @@ def build_requirements(self): if self.settings.compiler == "Visual Studio": self.build_requires("cccl/1.1") if tools.os_info.is_windows: - self.build_requires("winflexbison/2.5.18@bincrafters/stable") + self.build_requires("winflexbison/2.5.22") else: self.build_requires("bison/3.5.3") self.build_requires("automake/1.16.2") From 409b5d97014b04c05bdecdfd909aa0996b1bc0ec Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Sat, 23 May 2020 18:36:18 +0200 Subject: [PATCH 3/7] swig: fix test for msys2 in build_requirements --- recipes/swig/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/swig/all/conanfile.py b/recipes/swig/all/conanfile.py index 18ecbbc5323f0..475dae4faf7c6 100644 --- a/recipes/swig/all/conanfile.py +++ b/recipes/swig/all/conanfile.py @@ -25,7 +25,7 @@ def configure(self): def build_requirements(self): if tools.os_info.is_windows and not tools.get_env("CONAN_BASH_PATH") \ - and not tools.os_info.detect_windows_subsystem() != "msys2": + and tools.os_info.detect_windows_subsystem() != "msys2": self.build_requires("msys2/20190524") if self.settings.compiler == "Visual Studio": self.build_requires("cccl/1.1") From 07e642b05479164a5c0d9492f831f634da9484ec Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 29 May 2020 15:56:35 +0200 Subject: [PATCH 4/7] swig: add build_type to settings to avoid debug build_type --- recipes/swig/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/swig/all/conanfile.py b/recipes/swig/all/conanfile.py index 475dae4faf7c6..f50d8fdf27ba2 100644 --- a/recipes/swig/all/conanfile.py +++ b/recipes/swig/all/conanfile.py @@ -11,7 +11,7 @@ class SwigConan(ConanFile): license = "GPL-3.0-or-later" topics = ("conan", "swig", "python", "java", "wrapper") exports_sources = "patches/**" - settings = "os", "arch", "compiler" + settings = "os", "arch", "compiler", "build_type" _autotools = None From 2a0364bdff32923081857e6e01d8df4031b69e4c Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 29 May 2020 19:48:45 +0200 Subject: [PATCH 5/7] swig: use automake instead of cccl + include compiler in build_id (to avoid debug runtime) --- recipes/swig/all/conanfile.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/recipes/swig/all/conanfile.py b/recipes/swig/all/conanfile.py index f50d8fdf27ba2..d0e3e40aad9ef 100644 --- a/recipes/swig/all/conanfile.py +++ b/recipes/swig/all/conanfile.py @@ -11,7 +11,7 @@ class SwigConan(ConanFile): license = "GPL-3.0-or-later" topics = ("conan", "swig", "python", "java", "wrapper") exports_sources = "patches/**" - settings = "os", "arch", "compiler", "build_type" + settings = "os", "arch", "compiler" _autotools = None @@ -27,8 +27,6 @@ def build_requirements(self): if tools.os_info.is_windows and not tools.get_env("CONAN_BASH_PATH") \ and tools.os_info.detect_windows_subsystem() != "msys2": self.build_requires("msys2/20190524") - if self.settings.compiler == "Visual Studio": - self.build_requires("cccl/1.1") if tools.os_info.is_windows: self.build_requires("winflexbison/2.5.22") else: @@ -44,22 +42,24 @@ def source(self): @contextmanager def _build_context(self): - extra_env = { - "CONAN_CPU_COUNT": "1" if self.settings.compiler == "Visual Studio" else str(tools.cpu_count()), - } - with tools.environment_append(extra_env): - if self.settings.compiler == "Visual Studio": - with tools.vcvars(self.settings): + if self.settings.compiler == "Visual Studio": + with tools.vcvars(self.settings): + env = { + "CC": "{} cl -nologo".format(tools.unix_path(self.deps_user_info["automake"].compile)), + "CXX": "{} cl -nologo".format(tools.unix_path(self.deps_user_info["automake"].compile)), + "AR": "{} link".format(self.deps_user_info["automake"].ar_lib), + "LD": "link", + } + with tools.environment_append(env): yield - else: - yield + else: + yield def _configure_autotools(self): if self._autotools: return self._autotools self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) - deps_libpaths = self._autotools.library_paths deps_libs = self._autotools.libs deps_defines = self._autotools.defines @@ -76,6 +76,10 @@ def _configure_autotools(self): if self.settings.compiler == "Visual Studio": self.output.warn("Visual Studio compiler cannot create ccache-swig. Disabling ccache-swig.") args.append("--disable-ccache") + self._autotools.flags.append("-FS") + + self._autotools.libs = [] + self._autotools.library_paths = [] self._autotools.configure(args=args, configure_dir=self._source_subfolder) return self._autotools @@ -107,9 +111,6 @@ def package(self): self.run("{} swig{}".format(strip, ext), win_bash=tools.os_info.is_windows) self.run("{} ccache-swig{}".format(strip, ext), win_bash=tools.os_info.is_windows) - def package_id(self): - del self.info.settings.compiler - @property def _swiglibdir(self): return os.path.join(self.package_folder, "bin", "swiglib").replace("\\", "/") From 84ad51109b94675dc71ab11db2b8c7afcfa4de0b Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 29 May 2020 23:34:15 +0200 Subject: [PATCH 6/7] swig: remove compiler version to reduce number of builds --- recipes/swig/all/conanfile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/recipes/swig/all/conanfile.py b/recipes/swig/all/conanfile.py index d0e3e40aad9ef..b01e61a08ff07 100644 --- a/recipes/swig/all/conanfile.py +++ b/recipes/swig/all/conanfile.py @@ -115,6 +115,10 @@ def package(self): def _swiglibdir(self): return os.path.join(self.package_folder, "bin", "swiglib").replace("\\", "/") + def package_id(self): + # Verilator is a executable-only package, so the compiler version does not matter + del self.info.settings.compiler.version + def package_info(self): # FIXME: Don't set cmake_find_package name because conan cmake generators do not define SWIG_EXECUTABLE # self.cpp_info.names["cmake_find_package"] = "SWIG" From 1e43ca8380396ea0af73e6379153a5aa9d62b2da Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 17 Jun 2020 04:09:54 +0200 Subject: [PATCH 7/7] swig: include all settings + do not remove compiler.version from package_id --- recipes/swig/all/conanfile.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/recipes/swig/all/conanfile.py b/recipes/swig/all/conanfile.py index b01e61a08ff07..1ea68c999d7df 100644 --- a/recipes/swig/all/conanfile.py +++ b/recipes/swig/all/conanfile.py @@ -11,7 +11,7 @@ class SwigConan(ConanFile): license = "GPL-3.0-or-later" topics = ("conan", "swig", "python", "java", "wrapper") exports_sources = "patches/**" - settings = "os", "arch", "compiler" + settings = "os", "arch", "compiler", "build_type" _autotools = None @@ -115,10 +115,6 @@ def package(self): def _swiglibdir(self): return os.path.join(self.package_folder, "bin", "swiglib").replace("\\", "/") - def package_id(self): - # Verilator is a executable-only package, so the compiler version does not matter - del self.info.settings.compiler.version - def package_info(self): # FIXME: Don't set cmake_find_package name because conan cmake generators do not define SWIG_EXECUTABLE # self.cpp_info.names["cmake_find_package"] = "SWIG"