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 all 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
9 changes: 9 additions & 0 deletions recipes/jsonnet/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.4)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

add_subdirectory(source_subfolder)
10 changes: 10 additions & 0 deletions recipes/jsonnet/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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/0001-fix-nlohmann-include.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-cmake-fixes.patch"
base_path: "source_subfolder"
89 changes: 89 additions & 0 deletions recipes/jsonnet/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration

required_conan_version = ">=1.33.0"


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,
}
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 config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

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 tools.cross_building(self, skip_x64_x86=True):
raise ConanInvalidConfiguration("jsonnet does not support cross building")

if self.settings.compiler.cppstd:
uilianries marked this conversation as resolved.
Show resolved Hide resolved
tools.check_min_cppstd(self, "11")

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

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)
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", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
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.stdcpp_library(self):
self.cpp_info.components["libjsonnet"].system_libs.append(tools.stdcpp_library(self))
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["libjsonnet"].system_libs.append("m")

self.cpp_info.components["libjsonnetpp"].libs = ["jsonnet++"]
self.cpp_info.components["libjsonnetpp"].requires = ["libjsonnet"]
11 changes: 11 additions & 0 deletions recipes/jsonnet/all/patches/0001-fix-nlohmann-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"
87 changes: 87 additions & 0 deletions recipes/jsonnet/all/patches/0002-cmake-fixes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
- 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
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
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
- PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+ 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 @@
set(LIBJSONNETPP_HEADERS
../include/libjsonnet++.h
)
-
+install(FILES ${LIBJSONNETPP_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
set(LIBJSONNETPP_SOURCE
libjsonnet++.cpp
)
-
+if (NOT BUILD_STATIC_LIBS)
add_library(libjsonnet++ SHARED ${LIBJSONNETPP_HEADERS} ${LIBJSONNETPP_SOURCE})
add_dependencies(libjsonnet++ jsonnet)
-# target_link_libraries(libjsonnet libjsonnet)
+target_link_libraries(libjsonnet++ libjsonnet)
@@ -24,7 +24,7 @@
- PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+ 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 ${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 @@
# Custom command that will only build stdlib when it changes.
add_custom_command(
OUTPUT ${PROJECT_SOURCE_DIR}/core/std.jsonnet.h
- COMMAND ${GLOBAL_OUTPUT_PATH}/to_c_array
+ COMMAND to_c_array
${PROJECT_SOURCE_DIR}/stdlib/std.jsonnet
${PROJECT_SOURCE_DIR}/core/std.jsonnet.h
DEPENDS to_c_array std.jsonnet)


12 changes: 12 additions & 0 deletions recipes/jsonnet/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

add_executable(${PROJECT_NAME}_c test_package.c)
target_link_libraries(${PROJECT_NAME}_c ${CONAN_LIBS})

add_executable(${PROJECT_NAME}_cxx test_package.cpp)
target_link_libraries(${PROJECT_NAME}_cxx ${CONAN_LIBS})
set_property(TARGET ${PROJECT_NAME}_cxx PROPERTY 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"

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

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

#include <stdio.h>

int main() {
struct JsonnetVm* vm = jsonnet_make();
jsonnet_max_stack(vm, 10);
printf("%s\n", jsonnet_version());
return 0;
}

13 changes: 13 additions & 0 deletions recipes/jsonnet/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#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

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