Skip to content

Commit

Permalink
Merge pull request #691 from luketpeterson/open-ssl-dynamic-link
Browse files Browse the repository at this point in the history
Adds support for git-based catalogs, explicit git-based modules, managed catalogs, and fixes build without pkg_mgmt feature set
  • Loading branch information
vsbogd authored Jun 7, 2024
2 parents 27bc9df + 728c100 commit 7c6740f
Show file tree
Hide file tree
Showing 31 changed files with 2,852 additions and 861 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ project(hyperon)

include(ExternalProject)

option(GIT "Adds git features to hyperon library; requires OpenSSL and Zlib" ON)

set(HYPERONC_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/hyperonc-prefix")
message(STATUS "HYPERONC_INSTALL_PREFIX = ${HYPERONC_INSTALL_PREFIX}")

Expand All @@ -17,6 +19,7 @@ ExternalProject_Add(
PREFIX "${HYPERONC_INSTALL_PREFIX}"
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/c"
CMAKE_ARGS
-DGIT=${GIT}
"-DCMAKE_INSTALL_PREFIX=${HYPERONC_INSTALL_PREFIX}"
"-DCMAKE_BUILD_TYPE=${BUILD_CONFIGURATION}"
"-DCARGO_ARGS=${CARGO_ARGS}"
Expand All @@ -32,6 +35,7 @@ ExternalProject_Add(
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/python"
DEPENDS hyperonc
CMAKE_ARGS
-DGIT=${GIT}
"-DHYPERONC_INSTALL_PREFIX=${HYPERONC_INSTALL_PREFIX}"
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}/python"
"-DCMAKE_BUILD_TYPE=${BUILD_CONFIGURATION}"
Expand Down
15 changes: 15 additions & 0 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
cmake_minimum_required(VERSION 3.19)
project(hyperonc)

option(GIT "Adds git features to hyperon library; requires OpenSSL and Zlib" ON)

enable_testing()
option(BUILD_SHARED_LIBS "Build shared library" ON)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
Expand Down Expand Up @@ -34,10 +36,15 @@ set(HYPERONC_STATIC_LIB_PATH ${HYPERONC_TARGET_DIR}/${HYPERONC_STATIC_LIB_FILE})
set(HYPERONC_INCLUDE_DIR ${HYPERONC_TARGET_DIR}/hyperon)
separate_arguments(CARGO_ARGS_LIST NATIVE_COMMAND ${CARGO_ARGS})

if(GIT)
set(GIT_FEATURE --features hyperon/git)
endif()

add_custom_target(build-hyperonc ALL
COMMAND cargo build
${CARGO_ARGS_LIST}
$<${IS_RELEASE_BUILD}:--release>
${GIT_FEATURE}
--target-dir ${HYPERONC_TARGET_DIR}

COMMAND ${CMAKE_COMMAND} -E copy
Expand Down Expand Up @@ -71,6 +78,11 @@ set(STATIC_LIBRARY_INSTALL_PATH "${BINARY_INSTALL_PATH}/${HYPERONC_STATIC_LIB_FI
include(CMakePackageConfigHelpers)

if(BUILD_SHARED_LIBS)
if(GIT)
find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)
endif(GIT)

set(HYPERONC_SHARED_LIB_FILE ${CMAKE_SHARED_LIBRARY_PREFIX}hyperonc${CMAKE_SHARED_LIBRARY_SUFFIX})
set(HYPERONC_SHARED_LIB_PATH ${HYPERONC_TARGET_DIR}/${HYPERONC_SHARED_LIB_FILE})
set(SHARED_LIBRARY_INSTALL_PATH "${BINARY_INSTALL_PATH}/${HYPERONC_SHARED_LIB_FILE}")
Expand All @@ -90,6 +102,9 @@ if(BUILD_SHARED_LIBS)
# required to import hyperonc-shared by name not by relative path
IMPORTED_NO_SONAME TRUE
)
if(GIT)
target_link_libraries(hyperonc-shared INTERFACE OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB)
endif(GIT)
add_dependencies(hyperonc-shared copy-hyperonc-shared build-hyperonc)

install(FILES "${HYPERONC_SHARED_LIB_PATH}"
Expand Down
17 changes: 11 additions & 6 deletions c/src/metta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use hyperon::metta::interpreter;
use hyperon::metta::interpreter::InterpreterState;
use hyperon::metta::runner::{Metta, RunContext, RunnerState, Environment, EnvBuilder};
use hyperon::metta::runner::modules::{ModuleLoader, ModId, ResourceKey};
use hyperon::metta::runner::modules::catalog::{FsModuleFormat, ModuleDescriptor};
use hyperon::metta::runner::pkg_mgmt::{FsModuleFormat, ModuleDescriptor};
use hyperon::atom::*;

use crate::util::*;
Expand Down Expand Up @@ -1566,15 +1566,16 @@ pub extern "C" fn env_builder_set_config_dir(builder: *mut env_builder_t, path:
*builder_arg_ref = builder.into();
}

/// @brief Configures the environment to create the config dir if it doesn't already exist
/// @brief Sets whether the config dir should be created if it doesn't already exist
/// @ingroup environment_group
/// @param[in] builder A pointer to the in-process environment builder state
/// @param[in] should_create Whether the directory will be created. Defaults to `true`
///
#[no_mangle]
pub extern "C" fn env_builder_create_config_dir(builder: *mut env_builder_t) {
pub extern "C" fn env_builder_create_config_dir(builder: *mut env_builder_t, should_create: bool) {
let builder_arg_ref = unsafe{ &mut *builder };
let builder = core::mem::replace(builder_arg_ref, env_builder_t::null()).into_inner();
let builder = builder.create_config_dir();
let builder = builder.set_create_config_dir(should_create);
*builder_arg_ref = builder.into();
}

Expand Down Expand Up @@ -1738,7 +1739,8 @@ pub extern "C" fn module_id_is_valid(mod_id: *const module_id_t) -> bool {
///
#[no_mangle]
pub extern "C" fn module_descriptor_new(name: *const c_char) -> module_descriptor_t {
ModuleDescriptor::new(cstr_as_str(name).to_string()).into()
//TODO-NEXT: We should probably take a version string, and parse it into a semver version
ModuleDescriptor::new(cstr_as_str(name).to_string(), None, None).into()
}

/// @brief Creates a new module_descriptor_t that represents the error attempting to interpret a module
Expand Down Expand Up @@ -1906,7 +1908,10 @@ impl FsModuleFormat for CFsModFmtLoader {

let result_context = (api.try_path)(self.payload, path_c_string.as_ptr(), mod_name_c_string.as_ptr());
if !result_context.is_null() {
let descriptor = ModuleDescriptor::new_with_path_and_fmt_id(mod_name.to_string(), path, self.fmt_id);
//TODO-NEXT. We want to provide a way for the loader to support loading a PkgInfo, and also pass
// the version from that PkgInfo when the new descriptor is created

let descriptor = ModuleDescriptor::new_with_path_and_fmt_id(mod_name.to_string(), None, path, self.fmt_id);

let mut new_loader = self.clone();
new_loader.callback_context = result_context;
Expand Down
11 changes: 6 additions & 5 deletions c/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ set(TEST_SOURCES
c_space.c
util.c
)

add_executable(check_atom check_atom.c ${TEST_SOURCES})
target_link_libraries(check_atom hyperonc-static CONAN_PKG::libcheck)
target_link_libraries(check_atom hyperonc-shared CONAN_PKG::libcheck)
add_test(NAME check_atom COMMAND check_atom)

add_executable(check_space check_space.c ${TEST_SOURCES})
target_link_libraries(check_space hyperonc-static CONAN_PKG::libcheck)
target_link_libraries(check_space hyperonc-shared CONAN_PKG::libcheck)
add_test(NAME check_space COMMAND check_space)

add_executable(check_sexpr_parser check_sexpr_parser.c ${TEST_SOURCES})
target_link_libraries(check_sexpr_parser hyperonc-static CONAN_PKG::libcheck)
target_link_libraries(check_sexpr_parser hyperonc-shared CONAN_PKG::libcheck)
add_test(NAME check_sexpr_parser COMMAND check_sexpr_parser)

add_executable(check_types check_types.c ${TEST_SOURCES})
target_link_libraries(check_types hyperonc-static CONAN_PKG::libcheck)
target_link_libraries(check_types hyperonc-shared CONAN_PKG::libcheck)
add_test(NAME check_types COMMAND check_types)

add_executable(check_runner check_runner.c ${TEST_SOURCES})
target_link_libraries(check_runner hyperonc-static CONAN_PKG::libcheck)
target_link_libraries(check_runner hyperonc-shared CONAN_PKG::libcheck)
add_test(NAME check_runner COMMAND check_runner)
2 changes: 1 addition & 1 deletion docs/modules_dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ More information on the individual module file formats is available in the MeTTa

## The PkgInfo Structure

Each module has an associated [PkgInfo] structure, which provides the module author a place to specify meta-data about the module and express requirements for the module's dependencies. Additionally a [PkgInfo] can provide explicit loading instructions such as file system paths or github URIs for dependent modules. The [PkgInfo] structure is the same concept as the Cargo.toml file used in Cargo/Rust.
Each module has an associated [PkgInfo] structure, which provides the module author a place to specify meta-data about the module and express requirements for the module's dependencies. Additionally a [PkgInfo] can provide explicit loading instructions such as file system paths or github URLs for dependent modules. The [PkgInfo] structure is the same concept as the Cargo.toml file used in Cargo/Rust.

The [PkgInfo] should be initialized inside the module's loader function. If it is not initialized then default values will be used.

Expand Down
11 changes: 9 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ env_logger = { workspace = true }
directories = "5.0.1" # For Environment to find platform-specific config location
smallvec = "1.10.0"
im = "15.1.0"
xxhash-rust = {version="0.8.7", features=["xxh3"], optional=true}
rand = "0.8.5"
bitset = "0.1.2"
dyn-fmt = "0.4.0"

# pkg_mgmt deps
xxhash-rust = {version="0.8.7", features=["xxh3"], optional=true }
serde = { version="1.0.198", features = ["derive"], optional=true }
serde_json = { version="1.0.116", optional=true }
semver = { version="1.0", features = ["serde"], optional=true }
git2 = { version="0.18.3", features=["vendored-libgit2"], optional=true }

[lib]
name = "hyperon"
path = "src/lib.rs"
Expand All @@ -27,4 +33,5 @@ default = ["pkg_mgmt"]
minimal = [] # enables minimal MeTTa interpreter
variable_operation = [] # enables evaluation of the expressions which have
# a variable on the first position
pkg_mgmt = ["xxhash-rust"]
git = ["git2", "pkg_mgmt"]
pkg_mgmt = ["xxhash-rust", "serde", "serde_json", "semver"]
Loading

0 comments on commit 7c6740f

Please sign in to comment.