sqlite package: support Windows build (#41924)
Resubmission of #41761 with proper relocation of get_arch (taken from #41824). Co-authored-by: vsoch <vsochat@stanford.edu>
This commit is contained in:
		| @@ -10,12 +10,13 @@ | |||||||
| from spack.package import * | from spack.package import * | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Sqlite(AutotoolsPackage): | class Sqlite(AutotoolsPackage, NMakePackage): | ||||||
|     """SQLite is a C-language library that implements a small, fast, |     """SQLite is a C-language library that implements a small, fast, | ||||||
|     self-contained, high-reliability, full-featured, SQL database engine. |     self-contained, high-reliability, full-featured, SQL database engine. | ||||||
|     """ |     """ | ||||||
| 
 | 
 | ||||||
|     homepage = "https://www.sqlite.org" |     homepage = "https://www.sqlite.org" | ||||||
|  |     tags = ["windows"] | ||||||
| 
 | 
 | ||||||
|     license("blessing") |     license("blessing") | ||||||
| 
 | 
 | ||||||
| @@ -49,20 +50,40 @@ class Sqlite(AutotoolsPackage): | |||||||
|     # All versions prior to 3.26.0 are vulnerable to Magellan when FTS |     # All versions prior to 3.26.0 are vulnerable to Magellan when FTS | ||||||
|     # is enabled, see https://blade.tencent.com/magellan/index_en.html |     # is enabled, see https://blade.tencent.com/magellan/index_en.html | ||||||
| 
 | 
 | ||||||
|     variant( |     # no hard readline dep on Windows + no variant support, makefile has minimal to no options | ||||||
|         "functions", |     for plat in ["linux", "darwin", "cray", "freebsd"]: | ||||||
|         default=False, |         variant( | ||||||
|         when="+dynamic_extensions", |             "functions", | ||||||
|         description="Provide mathematical and string extension functions for SQL " |             default=False, | ||||||
|         "queries using the loadable extensions mechanism", |             description="Provide mathematical and string extension functions for SQL " | ||||||
|     ) |             "queries using the loadable extensions mechanism", | ||||||
|     variant("fts", default=True, description="Include fts4 and fts5 support") |             when=f"+dynamic_extensions platform={plat}", | ||||||
|     variant("column_metadata", default=True, description="Build with COLUMN_METADATA") |         ) | ||||||
|     variant("dynamic_extensions", default=True, description="Support loadable extensions") |         variant( | ||||||
|     variant("rtree", default=True, description="Build with Rtree module") |             "fts", | ||||||
|  |             default=True, | ||||||
|  |             description="Include fts4 and fts5 support", | ||||||
|  |             when=f"platform={plat}", | ||||||
|  |         ) | ||||||
|  |         variant( | ||||||
|  |             "column_metadata", | ||||||
|  |             default=True, | ||||||
|  |             description="Build with COLUMN_METADATA", | ||||||
|  |             when=f"platform={plat}", | ||||||
|  |         ) | ||||||
|  |         variant( | ||||||
|  |             "dynamic_extensions", | ||||||
|  |             default=True, | ||||||
|  |             description="Support loadable extensions", | ||||||
|  |             when=f"platform={plat}", | ||||||
|  |         ) | ||||||
|  |         variant( | ||||||
|  |             "rtree", default=True, description="Build with Rtree module", when=f"platform={plat}" | ||||||
|  |         ) | ||||||
|  |         depends_on("readline", when=f"platform={plat}") | ||||||
| 
 | 
 | ||||||
|     depends_on("readline") |  | ||||||
|     depends_on("zlib-api") |     depends_on("zlib-api") | ||||||
|  |     depends_on("tcl", when="platform=windows") | ||||||
| 
 | 
 | ||||||
|     # See https://blade.tencent.com/magellan/index_en.html |     # See https://blade.tencent.com/magellan/index_en.html | ||||||
|     conflicts("+fts", when="@:3.25") |     conflicts("+fts", when="@:3.25") | ||||||
| @@ -89,6 +110,10 @@ class Sqlite(AutotoolsPackage): | |||||||
|     # compiler is used. |     # compiler is used. | ||||||
|     patch("remove_overflow_builtins.patch", when="@3.17.0:3.20%intel") |     patch("remove_overflow_builtins.patch", when="@3.17.0:3.20%intel") | ||||||
| 
 | 
 | ||||||
|  |     patch("quote_compiler_in_makefile.patch", when="platform=windows") | ||||||
|  | 
 | ||||||
|  |     build_system("autotools", "nmake") | ||||||
|  | 
 | ||||||
|     executables = ["^sqlite3$"] |     executables = ["^sqlite3$"] | ||||||
| 
 | 
 | ||||||
|     @classmethod |     @classmethod | ||||||
| @@ -186,46 +211,6 @@ def url_for_version(self, version): | |||||||
|     def libs(self): |     def libs(self): | ||||||
|         return find_libraries("libsqlite3", root=self.prefix.lib) |         return find_libraries("libsqlite3", root=self.prefix.lib) | ||||||
| 
 | 
 | ||||||
|     def get_arch(self): |  | ||||||
|         host_platform = spack.platforms.host() |  | ||||||
|         return str(host_platform.target("default_target")) |  | ||||||
| 
 |  | ||||||
|     def configure_args(self): |  | ||||||
|         args = [] |  | ||||||
| 
 |  | ||||||
|         if self.get_arch() == "ppc64le": |  | ||||||
|             args.append("--build=powerpc64le-redhat-linux-gnu") |  | ||||||
| 
 |  | ||||||
|         args.extend(self.enable_or_disable("fts4", variant="fts")) |  | ||||||
|         args.extend(self.enable_or_disable("fts5", variant="fts")) |  | ||||||
| 
 |  | ||||||
|         # Ref: https://www.sqlite.org/rtree.html |  | ||||||
|         args.extend(self.enable_or_disable("rtree")) |  | ||||||
| 
 |  | ||||||
|         # Ref: https://www.sqlite.org/loadext.html |  | ||||||
|         args.extend(self.enable_or_disable("dynamic-extensions", variant="dynamic_extensions")) |  | ||||||
| 
 |  | ||||||
|         # Ref: https://www.sqlite.org/compile.html |  | ||||||
|         if "+column_metadata" in self.spec: |  | ||||||
|             args.append("CPPFLAGS=-DSQLITE_ENABLE_COLUMN_METADATA=1") |  | ||||||
| 
 |  | ||||||
|         return args |  | ||||||
| 
 |  | ||||||
|     @run_after("install") |  | ||||||
|     def build_libsqlitefunctions(self): |  | ||||||
|         if "+functions" in self.spec: |  | ||||||
|             libraryname = "libsqlitefunctions." + dso_suffix |  | ||||||
|             cc = Executable(spack_cc) |  | ||||||
|             cc( |  | ||||||
|                 self.compiler.cc_pic_flag, |  | ||||||
|                 "-lm", |  | ||||||
|                 "-shared", |  | ||||||
|                 "extension-functions.c", |  | ||||||
|                 "-o", |  | ||||||
|                 libraryname, |  | ||||||
|             ) |  | ||||||
|             install(libraryname, self.prefix.lib) |  | ||||||
| 
 |  | ||||||
|     def test_example(self): |     def test_example(self): | ||||||
|         """check example table dump""" |         """check example table dump""" | ||||||
| 
 | 
 | ||||||
| @@ -251,3 +236,61 @@ def test_version(self): | |||||||
|         sqlite3 = which(self.prefix.bin.sqlite3) |         sqlite3 = which(self.prefix.bin.sqlite3) | ||||||
|         out = sqlite3("-version", output=str.split, error=str.split) |         out = sqlite3("-version", output=str.split, error=str.split) | ||||||
|         assert vers_str in out |         assert vers_str in out | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class AutotoolsBuilder(spack.build_systems.autotools.AutotoolsBuilder): | ||||||
|  |     def configure_args(self): | ||||||
|  |         args = [] | ||||||
|  | 
 | ||||||
|  |         if self.get_arch() == "ppc64le": | ||||||
|  |             args.append("--build=powerpc64le-redhat-linux-gnu") | ||||||
|  | 
 | ||||||
|  |         args.extend(self.enable_or_disable("fts4", variant="fts")) | ||||||
|  |         args.extend(self.enable_or_disable("fts5", variant="fts")) | ||||||
|  | 
 | ||||||
|  |         # Ref: https://www.sqlite.org/rtree.html | ||||||
|  |         args.extend(self.enable_or_disable("rtree")) | ||||||
|  | 
 | ||||||
|  |         # Ref: https://www.sqlite.org/loadext.html | ||||||
|  |         args.extend(self.enable_or_disable("dynamic-extensions", variant="dynamic_extensions")) | ||||||
|  | 
 | ||||||
|  |         # Ref: https://www.sqlite.org/compile.html | ||||||
|  |         if "+column_metadata" in self.spec: | ||||||
|  |             args.append("CPPFLAGS=-DSQLITE_ENABLE_COLUMN_METADATA=1") | ||||||
|  | 
 | ||||||
|  |         return args | ||||||
|  | 
 | ||||||
|  |     def get_arch(self): | ||||||
|  |         host_platform = spack.platforms.host() | ||||||
|  |         return str(host_platform.target("default_target")) | ||||||
|  | 
 | ||||||
|  |     @run_after("install") | ||||||
|  |     def build_libsqlitefunctions(self): | ||||||
|  |         if "+functions" in self.spec: | ||||||
|  |             libraryname = "libsqlitefunctions." + dso_suffix | ||||||
|  |             cc = Executable(spack_cc) | ||||||
|  |             cc( | ||||||
|  |                 self.compiler.cc_pic_flag, | ||||||
|  |                 "-lm", | ||||||
|  |                 "-shared", | ||||||
|  |                 "extension-functions.c", | ||||||
|  |                 "-o", | ||||||
|  |                 libraryname, | ||||||
|  |             ) | ||||||
|  |             install(libraryname, self.prefix.lib) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class NMakeBuilder(spack.build_systems.nmake.NMakeBuilder): | ||||||
|  |     @property | ||||||
|  |     def makefile_name(self): | ||||||
|  |         return "Makefile.msc" | ||||||
|  | 
 | ||||||
|  |     def install(self, pkg, spec, prefix): | ||||||
|  |         with working_dir(self.build_directory): | ||||||
|  |             mkdirp(prefix.include) | ||||||
|  |             mkdirp(prefix.lib) | ||||||
|  |             mkdirp(prefix.bin) | ||||||
|  |             install(f"{self.build_directory}\\*.exe", prefix.bin) | ||||||
|  |             install(f"{self.build_directory}\\*.dll", prefix.bin) | ||||||
|  |             install(f"{self.build_directory}\\*.lib", prefix.lib) | ||||||
|  |             install(f"{self.build_directory}\\*.h", prefix.include) | ||||||
|   | |||||||
| @@ -0,0 +1,13 @@ | |||||||
|  | diff --git a/Makefile.msc b/Makefile.msc | ||||||
|  | index 95f0eee0d..8fc173e98 100644 | ||||||
|  | --- a/Makefile.msc | ||||||
|  | +++ b/Makefile.msc | ||||||
|  | @@ -441,6 +441,8 @@ PROGRAMFILES_X86 = $(PROGRAMFILES_X86:\\=\) | ||||||
|  |  # | ||||||
|  |  !IFNDEF CC | ||||||
|  |  CC = cl.exe | ||||||
|  | +!ELSE | ||||||
|  | +CC = "$(CC)" | ||||||
|  |  !ENDIF | ||||||
|  |   | ||||||
|  |  # Check for the predefined command macro CSC.  This should point to a working | ||||||
		Reference in New Issue
	
	Block a user
	 John W. Parent
					John W. Parent