Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jsonnet/0.17.0 #6099

Merged
merged 23 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
7 changes: 7 additions & 0 deletions recipes/jsonnet/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
12 changes: 12 additions & 0 deletions recipes/jsonnet/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sources:
"0.17.0":
sha256: "076b52edf888c01097010ad4299e3b2e7a72b60a41abbc65af364af1ed3c8dbe"
url: "https://github.com/google/jsonnet/archive/v0.17.0.tar.gz"
patches:
"0.17.0":
- patch_file: "patches/fix-core-static-lib.patch"
base_path: "source_subfolder"
- patch_file: "patches/fix-cpp-static-lib.patch"
base_path: "source_subfolder"
- patch_file: "patches/fix-include.patch"
base_path: "source_subfolder"
77 changes: 77 additions & 0 deletions recipes/jsonnet/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration


class JsonnetConan(ConanFile):
name = "jsonnet"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/google/jsonnet"
description = "Jsonnet - The data templating language"
topics = ("config", "json", "functional", "configuration")
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
vcampmany marked this conversation as resolved.
Show resolved Hide resolved
generators = "cmake", "cmake_find_package"
exports_sources = ["CMakeLists.txt", "patches/*"]
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

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

def configure(self):
if self.options.shared:
del self.options.fPIC

def requirements(self):
self.requires("nlohmann_json/3.9.1")

def validate(self):
if self.settings.compiler not in ["gcc", "clang", "apple-clang"]:
raise ConanInvalidConfiguration("{} compiler not supported"
.format(self.settings.compiler))
if self.settings.compiler.cppstd:
uilianries marked this conversation as resolved.
Show resolved Hide resolved
tools.check_min_cppstd(self, "11")

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

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_TESTS"] = False
self._cmake.definitions["BUILD_STATIC_LIBS"] = not self.options.shared
self._cmake.definitions["BUILD_JSONNET"] = False
self._cmake.definitions["BUILD_JSONNETFMT"] = False
uilianries marked this conversation as resolved.
Show resolved Hide resolved
self._cmake.definitions["USE_SYSTEM_JSON"] = True
self._cmake.configure(build_folder=self._build_subfolder,
source_folder=self._source_subfolder)
return self._cmake

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

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()

def package_info(self):
self.cpp_info.libs = ["jsonnet++", "jsonnet"]
self.cpp_info.names["cmake_find_package"] = "jsonnet"
self.cpp_info.names["cmake_find_package_multi"] = "jsonnet"
self.cpp_info.names["pkg_config"] = "jsonnet"
84 changes: 84 additions & 0 deletions recipes/jsonnet/all/patches/fix-core-static-lib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -15,7 +15,8 @@
static_error.h
string_utils.h
unicode.h
- vm.h)
+ vm.h
+ ../third_party/md5/md5.h)

set(LIBJSONNET_SOURCE
desugarer.cpp
@@ -26,40 +27,44 @@
pass.cpp
static_analysis.cpp
string_utils.cpp
- vm.cpp)
+ vm.cpp
+ ../third_party/md5/md5.cpp)

-add_library(libjsonnet SHARED ${LIBJSONNET_HEADERS} ${LIBJSONNET_SOURCE})
-add_dependencies(libjsonnet md5 stdlib)
-target_link_libraries(libjsonnet md5 nlohmann_json::nlohmann_json)
-
-file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/../include/libjsonnet.h JSONNET_VERSION_DEF
- REGEX "[#]define[ \t]+LIB_JSONNET_VERSION[ \t]+")
-string(REGEX REPLACE ".*\"v([^\"]+)\".*" "\\1" JSONNET_VERSION ${JSONNET_VERSION_DEF})
-message("Extracted Jsonnet version: " ${JSONNET_VERSION})
-
-
-# CMake prepends CMAKE_SHARED_LIBRARY_PREFIX to shared libraries, so without
-# this step the output would be |liblibjsonnet|.
-set_target_properties(libjsonnet PROPERTIES OUTPUT_NAME jsonnet
- VERSION "${JSONNET_VERSION}"
- SOVERSION "0"
- PUBLIC_HEADER "${LIB_HEADER}")
-install(TARGETS libjsonnet
- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
- PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
-target_include_directories(libjsonnet INTERFACE
- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)

-if (BUILD_STATIC_LIBS)
+if (NOT BUILD_STATIC_LIBS)
+ add_library(libjsonnet SHARED ${LIBJSONNET_HEADERS} ${LIBJSONNET_SOURCE})
+ add_dependencies(libjsonnet stdlib)
+ target_link_libraries(libjsonnet nlohmann_json::nlohmann_json)
+
+ file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/../include/libjsonnet.h JSONNET_VERSION_DEF
+ REGEX "[#]define[ \t]+LIB_JSONNET_VERSION[ \t]+")
+ string(REGEX REPLACE ".*\"v([^\"]+)\".*" "\\1" JSONNET_VERSION ${JSONNET_VERSION_DEF})
+ message("Extracted Jsonnet version: " ${JSONNET_VERSION})
+
+
+ # CMake prepends CMAKE_SHARED_LIBRARY_PREFIX to shared libraries, so without
+ # this step the output would be |liblibjsonnet|.
+ set_target_properties(libjsonnet PROPERTIES OUTPUT_NAME jsonnet
+ VERSION "${JSONNET_VERSION}"
+ SOVERSION "0"
+ PUBLIC_HEADER "${LIB_HEADER}")
+ install(TARGETS libjsonnet
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+ target_include_directories(libjsonnet INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)
+else()
# Static library for jsonnet command-line tool.
add_library(libjsonnet_static STATIC ${LIBJSONNET_SOURCE})
- add_dependencies(libjsonnet_static md5 stdlib)
- target_link_libraries(libjsonnet_static md5 nlohmann_json::nlohmann_json)
+ add_dependencies(libjsonnet_static stdlib)
+ target_link_libraries(libjsonnet_static nlohmann_json::nlohmann_json)
set_target_properties(libjsonnet_static PROPERTIES OUTPUT_NAME jsonnet)
install(TARGETS libjsonnet_static DESTINATION "${CMAKE_INSTALL_LIBDIR}")
target_include_directories(libjsonnet_static INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../include/libjsonnet.h
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
endif()

if (BUILD_SHARED_BINARIES OR NOT BUILD_STATIC_LIBS)

56 changes: 56 additions & 0 deletions recipes/jsonnet/all/patches/fix-cpp-static-lib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -8,24 +8,24 @@
libjsonnet++.cpp
)

-add_library(libjsonnet++ SHARED ${LIBJSONNETPP_HEADERS} ${LIBJSONNETPP_SOURCE})
-add_dependencies(libjsonnet++ jsonnet)
-# target_link_libraries(libjsonnet libjsonnet)
+if (NOT BUILD_STATIC_LIBS)
uilianries marked this conversation as resolved.
Show resolved Hide resolved
+ add_library(libjsonnet++ SHARED ${LIBJSONNETPP_HEADERS} ${LIBJSONNETPP_SOURCE})
+ add_dependencies(libjsonnet++ jsonnet)
+ # target_link_libraries(libjsonnet libjsonnet)

-# CMake prepends CMAKE_SHARED_LIBRARY_PREFIX to shared libraries, so without
-# this step the output would be |liblibjsonnet|.
-set_target_properties(libjsonnet++ PROPERTIES OUTPUT_NAME jsonnet++
- VERSION "0.17.0"
- SOVERSION "0"
- PUBLIC_HEADER "${LIB_HEADER}")
-install(TARGETS libjsonnet++
- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
- PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
-target_include_directories(libjsonnet++ INTERFACE
- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)
-
-if (BUILD_STATIC_LIBS)
+ # CMake prepends CMAKE_SHARED_LIBRARY_PREFIX to shared libraries, so without
+ # this step the output would be |liblibjsonnet|.
+ set_target_properties(libjsonnet++ PROPERTIES OUTPUT_NAME jsonnet++
+ VERSION "0.17.0"
+ SOVERSION "0"
+ PUBLIC_HEADER "${LIB_HEADER}")
+ install(TARGETS libjsonnet++
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+ target_include_directories(libjsonnet++ INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)
+else()
# Static library for jsonnet command-line tool.
add_library(libjsonnet++_static STATIC ${LIBJSONNETPP_SOURCE})
add_dependencies(libjsonnet++_static jsonnet)
@@ -34,6 +34,8 @@
install(TARGETS libjsonnet++_static DESTINATION "${CMAKE_INSTALL_LIBDIR}")
target_include_directories(libjsonnet++_static INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../include/libjsonnet++.h
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
endif()

if (BUILD_SHARED_BINARIES OR NOT BUILD_STATIC_LIBS)



11 changes: 11 additions & 0 deletions recipes/jsonnet/all/patches/fix-include.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/core/vm.cpp
+++ b/core/vm.cpp
@@ -23,7 +23,7 @@ limitations under the License.

#include "desugarer.h"
#include "json.h"
-#include "json.hpp"
+#include <nlohmann/json.hpp>
#include "md5.h"
#include "parser.h"
#include "state.h"
10 changes: 10 additions & 0 deletions recipes/jsonnet/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_executable(${PROJECT_NAME} test_package.cpp)

target_link_libraries(${PROJECT_NAME} CONAN_PKG::jsonnet)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11)
17 changes: 17 additions & 0 deletions recipes/jsonnet/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"

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

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
19 changes: 19 additions & 0 deletions recipes/jsonnet/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <libjsonnet++.h>
#include <libjsonnet.h>

#include <iostream>

int main() {
// C++ library
jsonnet::Jsonnet j;
if (!j.init()) {
return 1;
}
std::cout << jsonnet::Jsonnet::version() << "\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::cout << jsonnet::Jsonnet::version() << "\n";
std::cout << jsonnet::Jsonnet::version() << "\n";

It's not available for GCC5 + libstdc++. Only works with libstdc++11

Besides that, both libjsonnet++.so and libjsonnet.so require libstdc++

ldd lib/libjsonnet.so
linux-vdso.so.1 => (0x00007ffde2908000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f8b93523000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8b9321a000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f8b93004000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8b92c3a000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8b93b75000)

ldd lib/libjsonnet++.so
linux-vdso.so.1 => (0x00007ffc61d7f000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa4dc271000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa4dc05b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa4dbc91000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa4db988000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa4dc7f7000)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly is not available? I don't see what have you changed in your suggestion


// C library
struct JsonnetVm* vm = jsonnet_make();
jsonnet_max_stack(vm, 10);
std::cout << jsonnet_version() << "\n";
return 0;
}
3 changes: 3 additions & 0 deletions recipes/jsonnet/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.17.0":
folder: all