Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 0 additions & 9 deletions recipes/jsonnet/all/CMakeLists.txt

This file was deleted.

32 changes: 26 additions & 6 deletions recipes/jsonnet/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"0.20.0":
url: "https://github.com/google/jsonnet/archive/v0.20.0.tar.gz"
sha256: "77bd269073807731f6b11ff8d7c03e9065aafb8e4d038935deb388325e52511b"
"0.19.1":
url: "https://github.com/google/jsonnet/archive/v0.19.1.tar.gz"
sha256: "f5a20f2dc98fdebd5d42a45365f52fa59a7e6b174e43970fea4f9718a914e887"
Expand All @@ -9,18 +12,35 @@ sources:
url: "https://github.com/google/jsonnet/archive/v0.17.0.tar.gz"
sha256: "076b52edf888c01097010ad4299e3b2e7a72b60a41abbc65af364af1ed3c8dbe"
patches:
"0.20.0":
- patch_file: "patches/0.18.0/0001-fix-nlohmann-include.patch"
patch_description: "fix include path to use cci package"
patch_type: "conan"
- patch_file: "patches/0.18.0/0002-cmake-fixes.patch"
patch_description: "fix rapidyaml name, add installation"
patch_type: "conan"
- patch_file: "patches/0.20.0/0003-use-cpp17.patch"
patch_description: "use C++17"
patch_type: "portability"
patch_source: "https://github.com/google/jsonnet/pull/1076"
"0.19.1":
- patch_file: "patches/0.18.0/0001-fix-nlohmann-include.patch"
base_path: "source_subfolder"
patch_description: "fix include path to use cci package"
patch_type: "conan"
- patch_file: "patches/0.18.0/0002-cmake-fixes.patch"
base_path: "source_subfolder"
patch_description: "fix rapidyaml name, add installation"
patch_type: "conan"
"0.18.0":
- patch_file: "patches/0.18.0/0001-fix-nlohmann-include.patch"
base_path: "source_subfolder"
patch_description: "fix include path to use cci package"
patch_type: "conan"
- patch_file: "patches/0.18.0/0002-cmake-fixes.patch"
base_path: "source_subfolder"
patch_description: "fix rapidyaml name, add installation"
patch_type: "conan"
"0.17.0":
- patch_file: "patches/0.17.0/0001-fix-nlohmann-include.patch"
base_path: "source_subfolder"
patch_description: "fix include path to use cci package"
patch_type: "conan"
- patch_file: "patches/0.17.0/0002-cmake-fixes.patch"
base_path: "source_subfolder"
patch_description: "fix rapidyaml name, add installation"
patch_type: "conan"
130 changes: 76 additions & 54 deletions recipes/jsonnet/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import functools
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import is_msvc, msvc_runtime_flag
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy
from conan.tools.build import check_min_cppstd, cross_building, stdcpp_library
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
import os

required_conan_version = ">=1.33.0"

required_conan_version = ">=1.53.0"

class JsonnetConan(ConanFile):
name = "jsonnet"
description = "Jsonnet - The data templating language"
topics = ("config", "json", "functional", "configuration")
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/google/jsonnet"
topics = ("config", "json", "functional", "configuration")
settings = "os", "arch", "compiler", "build_type"
package_type = "library"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand All @@ -22,86 +26,104 @@ class JsonnetConan(ConanFile):
"shared": False,
"fPIC": True,
}
generators = "cmake", "cmake_find_package"

@property
def _source_subfolder(self):
return "source_subfolder"
def _min_cppstd(self):
return "11" if Version(self.version) < "0.20.0" else "17"

@property
def _build_subfolder(self):
return "build_subfolder"
def _compilers_minimum_version(self):
return {
"17": {
"gcc": "8",
"clang": "7",
"apple-clang": "12",
"Visual Studio": "16",
"msvc": "192",
},
}.get(self._min_cppstd, {})

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
# This is a workround.
# If jsonnet is shared, rapidyaml must be built as shared,
# or the c4core functions that rapidyaml depends on will not be able to be found.
# This seems to be a issue of rapidyaml.
# https://github.com/conan-io/conan-center-index/pull/9786#discussion_r829887879
if tools.Version(self.version) >= "0.18.0":
self.options["rapidyaml"].shared = True
self.options.rm_safe("fPIC")

def requirements(self):
self.requires("nlohmann_json/3.10.5")
if tools.Version(self.version) >= "0.18.0":
self.requires("rapidyaml/0.4.1")
def layout(self):
cmake_layout(self, src_folder="src")

def validate(self):
if hasattr(self, "settings_build") and tools.cross_building(self, skip_x64_x86=True):
raise ConanInvalidConfiguration("jsonnet does not support cross building")
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

if Version(self.version) == "0.17.0" and Version(self.settings.compiler.get_safe("cppstd")) > "17":
raise ConanInvalidConfiguration(f"{self.ref} does not support C++{self.settings.compiler.cppstd}")

if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, "11")
if hasattr(self, "settings_build") and cross_building(self, skip_x64_x86=True):
raise ConanInvalidConfiguration(f"{self.ref} does not support cross building")

if self.options.shared and is_msvc(self) and "d" in msvc_runtime_flag(self):
raise ConanInvalidConfiguration("shared {} is not supported with MTd/MDd runtime".format(self.name))
raise ConanInvalidConfiguration(f"shared {self.ref} is not supported with MTd/MDd runtime")

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
# This is a workround.
# If jsonnet is shared, rapidyaml must be built as shared,
# or the c4core functions that rapidyaml depends on will not be able to be found.
# This seems to be a issue of rapidyaml.
# https://github.com/conan-io/conan-center-index/pull/9786#discussion_r829887879
if self.options.shared and Version(self.version) >= "0.18.0" and self.dependencies["rapidyaml"].options.shared == False:
raise ConanInvalidConfiguration(f"shared {self.ref} requires rapidyaml to be built as shared")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
def requirements(self):
self.requires("nlohmann_json/3.11.2")
if Version(self.version) >= "0.18.0":
self.requires("rapidyaml/0.5.0")

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["BUILD_TESTS"] = False
cmake.definitions["BUILD_STATIC_LIBS"] = not self.options.shared
cmake.definitions["BUILD_SHARED_BINARIES"] = False
cmake.definitions["BUILD_JSONNET"] = False
cmake.definitions["BUILD_JSONNETFMT"] = False
cmake.definitions["USE_SYSTEM_JSON"] = True
cmake.configure(build_folder=self._build_subfolder)
return cmake
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_TESTS"] = False
tc.variables["BUILD_STATIC_LIBS"] = not self.options.shared
tc.variables["BUILD_SHARED_BINARIES"] = False
tc.variables["BUILD_JSONNET"] = False
tc.variables["BUILD_JSONNETFMT"] = False
tc.variables["USE_SYSTEM_JSON"] = True
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.components["libjsonnet"].libs = ["jsonnet"]
self.cpp_info.components["libjsonnet"].requires = ["nlohmann_json::nlohmann_json"]
if tools.Version(self.version) >= "0.18.0":
if Version(self.version) >= "0.18.0":
self.cpp_info.components["libjsonnet"].requires.append("rapidyaml::rapidyaml")

if tools.stdcpp_library(self):
self.cpp_info.components["libjsonnet"].system_libs.append(tools.stdcpp_library(self))
if stdcpp_library(self):
self.cpp_info.components["libjsonnet"].system_libs.append(stdcpp_library(self))
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["libjsonnet"].system_libs.append("m")

Expand Down
77 changes: 43 additions & 34 deletions recipes/jsonnet/all/patches/0.17.0/0002-cmake-fixes.patch
Original file line number Diff line number Diff line change
@@ -1,42 +1,56 @@
- install headers
- optionally disable shared build
- add md5 objects to c library
- allow MSVC
--- core/CMakeLists.txt
+++ core/CMakeLists.txt
@@ -16,8 +16,8 @@ set(LIBJSONNET_HEADERS
string_utils.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 385ea82..34b1c63 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,7 +40,7 @@ if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" OR
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++11 -fPIC ${OPT}")
else()
# TODO: Windows support.
- message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER_ID} not supported")
+ message(WARNING "Compiler ${CMAKE_CXX_COMPILER_ID} not supported")
endif()

set(CMAKE_CXX_STANDARD 11)
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index e8ad830..7d87527 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -17,7 +17,8 @@ set(LIBJSONNET_HEADERS
unicode.h
vm.h)
-
-set(LIBJSONNET_SOURCE
+install(FILES ../include/libjsonnet.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+set(LIBJSONNET_SOURCE $<TARGET_OBJECTS:md5>
desugarer.cpp
formatter.cpp
lexer.cpp
@@ -27,7 +27,7 @@ set(LIBJSONNET_SOURCE
static_analysis.cpp
@@ -28,6 +29,7 @@ set(LIBJSONNET_SOURCE
string_utils.cpp
vm.cpp)
-
+if (NOT BUILD_STATIC_LIBS)
add_library(libjsonnet SHARED ${LIBJSONNET_HEADERS} ${LIBJSONNET_SOURCE})
add_dependencies(libjsonnet md5 stdlib)
target_link_libraries(libjsonnet md5 nlohmann_json::nlohmann_json)
@@ -50,7 +50,7 @@ install(TARGETS libjsonnet
@@ -47,10 +49,10 @@ set_target_properties(libjsonnet PROPERTIES OUTPUT_NAME jsonnet
install(TARGETS libjsonnet
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
- PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+ PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
+ PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
target_include_directories(libjsonnet INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)
-
+endif()
if (BUILD_STATIC_LIBS)
# Static library for jsonnet command-line tool.
add_library(libjsonnet_static STATIC ${LIBJSONNET_SOURCE})
--- cpp/CMakeLists.txt
+++ cpp/CMakeLists.txt
@@ -3,11 +3,11 @@
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 5549902..3091a9c 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -3,14 +3,14 @@
set(LIBJSONNETPP_HEADERS
../include/libjsonnet++.h
)
Expand All @@ -51,7 +65,13 @@
add_dependencies(libjsonnet++ jsonnet)
-# target_link_libraries(libjsonnet libjsonnet)
+target_link_libraries(libjsonnet++ libjsonnet)
@@ -24,7 +24,7 @@

# CMake prepends CMAKE_SHARED_LIBRARY_PREFIX to shared libraries, so without
# this step the output would be |liblibjsonnet|.
@@ -21,10 +21,10 @@ set_target_properties(libjsonnet++ PROPERTIES OUTPUT_NAME jsonnet++
install(TARGETS libjsonnet++
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
- PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+ PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
target_include_directories(libjsonnet++ INTERFACE
Expand All @@ -61,20 +81,11 @@
if (BUILD_STATIC_LIBS)
# Static library for jsonnet command-line tool.
add_library(libjsonnet++_static STATIC ${LIBJSONNETPP_SOURCE})
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -40,7 +40,7 @@
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++11 -fPIC ${OPT}")
else()
# TODO: Windows support.
- message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER_ID} not supported")
+ message(WARNING "Compiler ${CMAKE_CXX_COMPILER_ID} not supported")
endif()

set(CMAKE_CXX_STANDARD 11)
--- stdlib/CMakeLists.txt
+++ stdlib/CMakeLists.txt
@@ -5,7 +5,7 @@
diff --git a/stdlib/CMakeLists.txt b/stdlib/CMakeLists.txt
index a481d9f..00ff502 100644
--- a/stdlib/CMakeLists.txt
+++ b/stdlib/CMakeLists.txt
@@ -5,7 +5,7 @@ add_executable(to_c_array to_c_array.cpp)
# Custom command that will only build stdlib when it changes.
add_custom_command(
OUTPUT ${PROJECT_SOURCE_DIR}/core/std.jsonnet.h
Expand All @@ -83,5 +94,3 @@
${PROJECT_SOURCE_DIR}/stdlib/std.jsonnet
${PROJECT_SOURCE_DIR}/core/std.jsonnet.h
DEPENDS to_c_array std.jsonnet)


Loading