Skip to content

Commit

Permalink
Merge branch 'main' into yziquel
Browse files Browse the repository at this point in the history
  • Loading branch information
vsbogd authored Jul 31, 2024
2 parents a9accc8 + 43b7230 commit d4774ff
Show file tree
Hide file tree
Showing 21 changed files with 778 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-auto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
with:
python-version: "3.7"
os: "ubuntu-20.04"
cmake-version: "3.19.x"
cmake-version: "3.24.x"
2 changes: 1 addition & 1 deletion .github/workflows/ci-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:
cmake-version:
description: 'JSON array of CMake versions to be checked'
required: true
default: "[\"3.19.x\"]"
default: "[\"3.24.x\"]"
type: string

jobs:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:
type: string
cmake-version:
description: "CMake version to use"
default: "3.19.x"
default: "3.24.x"
required: false
type: string

Expand Down Expand Up @@ -69,11 +69,11 @@ jobs:
- name: Install Conan
uses: turtlebrowser/[email protected]
with:
version: "1.64"
version: "2.5.0"

- name: Setup Conan profile
run: |
conan profile new --detect default
conan profile detect --force
- name: Print environment
run: |
Expand All @@ -97,8 +97,8 @@ jobs:
echo "conan Python: $conan_python"
echo -n "conan Python platform: "
$conan_python -c "import platform; print(platform.platform())"
echo "conan profile show default"
conan profile show default
echo "conan profile show"
conan profile show
echo "gcc --version"
gcc --version
echo "g++ --version"
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/old_interpreter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ jobs:
- name: Install CMake
uses: jwlawson/[email protected]
with:
cmake-version: "3.19.x"
cmake-version: "3.24.x"

- name: Install Conan
uses: turtlebrowser/[email protected]
with:
version: "1.64"
version: "2.5.0"

- name: Setup Conan profile
run: |
conan profile new --detect default
conan profile detect --force
- name: Print environment
run: |
Expand All @@ -87,8 +87,8 @@ jobs:
echo "conan Python: $conan_python"
echo -n "conan Python platform: "
$conan_python -c "import platform; print(platform.platform())"
echo "conan profile show default"
conan profile show default
echo "conan profile show"
conan profile show
echo "gcc --version"
gcc --version
echo "g++ --version"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Cargo.lock
.vscode
.aider*
__pycache__
CMakeUserPresets.json
/build
/python/hyperon.egg-info
/python/dist
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Minimal version supported by hyperonc
cmake_minimum_required(VERSION 3.19)
cmake_minimum_required(VERSION 3.24)

project(hyperon)

Expand All @@ -22,6 +22,7 @@ ExternalProject_Add(
"-DCMAKE_INSTALL_PREFIX=${HYPERONC_INSTALL_PREFIX}"
"-DCMAKE_BUILD_TYPE=${BUILD_CONFIGURATION}"
"-DCARGO_ARGS=${CARGO_ARGS}"
"-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=${CMAKE_CURRENT_SOURCE_DIR}/conan_provider.cmake"
)

ExternalProject_Get_Property(hyperonc BINARY_DIR)
Expand All @@ -38,6 +39,7 @@ ExternalProject_Add(
"-DHYPERONC_INSTALL_PREFIX=${HYPERONC_INSTALL_PREFIX}"
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}/python"
"-DCMAKE_BUILD_TYPE=${BUILD_CONFIGURATION}"
"-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=${CMAKE_CURRENT_SOURCE_DIR}/conan_provider.cmake"
INSTALL_COMMAND cmake -E echo "Skipping install step."
)

Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ RUN sh /tmp/rustup.sh -y && rm /tmp/rustup.sh
ENV PATH="${PATH}:${HOME}/.cargo/bin"
RUN cargo install cbindgen

RUN python3 -m pip install conan==1.64 pip==23.1.2
RUN python3 -m pip install conan==2.5.0 pip==23.1.2
ENV PATH="${PATH}:${HOME}/.local/bin"
RUN conan profile new --detect default
RUN conan profile detect --force

ADD --chown=user:users . ${HOME}/hyperon-experimental

WORKDIR ${HOME}/hyperon-experimental
RUN cargo test --release
RUN cargo build --release
RUN cargo build --features python,git --release

ENV BUILD=${HOME}/hyperon-experimental/build
RUN mkdir ${BUILD}
Expand Down
60 changes: 47 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ page](https://www.rust-lang.org/tools/install). Make sure your
Rust (see the Notes at the installation page).

Requirements for building C and Python API
* Python3 and Python3-dev (3.7 or later, but not 3.12)
* Python3 and Python3-dev (3.7 or later)
* Pip (23.1.2 or later)
* GCC (7.5 or later)
* CMake (3.19 or later)
* CMake (3.24 or later)

To support Git based modules (enabled by default):
* OpenSSL library
Expand All @@ -99,8 +99,8 @@ cargo install --force cbindgen

* Install Conan and make default Conan profile:
```
python3 -m pip install conan==1.64
conan profile new --detect default
python3 -m pip install conan==2.5.0
conan profile detect --force
```

* Upgrade Pip to the required version:
Expand Down Expand Up @@ -135,7 +135,7 @@ cargo run --example sorted_list

Run Rust REPL:
```
cargo run --features no_python --bin metta-repl
cargo run --bin metta-repl
```
You can also find executable at `./target/debug/metta-repl`.

Expand Down Expand Up @@ -193,10 +193,12 @@ metta-py ./tests/scripts/<name>.metta

Run REPL:
```
cargo run --bin metta-repl
cargo run --features python --bin metta-repl
```
You can also find executable at `./target/debug/metta-repl`.

Running the REPL with Python support in a Python virtual environment like PyEnv or Conda requires additional configuration. See [troubleshooting](#rust-repl-cannot-load-python-library)

### Logger

You can enable logging by prefixing the MeTTa command line by
Expand Down Expand Up @@ -236,21 +238,19 @@ If you see the following `cmake` output:
```
ERROR: Not able to automatically detect '/usr/bin/cc' version
ERROR: Unable to find a working compiler
WARN: Remotes registry file missing, creating default one in /root/.conan/remotes.json
ERROR: libcheck/0.15.2: 'settings.compiler' value not defined
```
Try to create the default Conan profile manually:
```
conan profile new --detect default
conan profile detect --force
```
If it doesn't help, then try to manually add `compiler`, `compiler.version` and
`compiler.libcxx` values in the default Conan profile
(`~/.conan/profiles/default`).
(`~/.conan2/profiles/default`).
For example:
```
conan profile update settings.compiler=gcc default
conan profile update settings.compiler.version=7 default
conan profile update settings.compiler.libcxx=libstdc++ default
compiler=gcc
compiler.version=7
compiler.libcxx=libstdc++
```

### Rust compiler shows errors
Expand All @@ -275,6 +275,40 @@ ModuleNotFoundError: No module named 'hyperonpy'
Please ensure you have installed the Python module, see
[Running Python and MeTTa examples](#running-python-and-metta-examples).

### Rust REPL cannot load Python library

The REPL needs a path to the libpython library in the current environment. This can be done one of two ways:

#### On Linux

##### Use `patchelf` on resulting REPL binary to link it with `libpython.so`
```
ldd target/debug/metta-repl | grep libpython ; to find <libpython-name>
patchelf --replace-needed <libpython-name> <path-to-libpython-in-virtual-env> target/debug/metta-repl
```
This must be redone each time the repl is rebuilt, e.g. with `cargo build`.

##### Set the `LD_LIBRARY_PATH` environment variable prior to launching `metta-repl`
```
export LD_LIBRARY_PATH=<path-to-libpython-directory-in-virtual-env>
```

#### On Mac OS
##### Use `install_name_tool` to change the REPL binary's link path for `libpython`
```
otool -L target/debug/metta-repl | grep libpython ; to find <libpython-name>
install_name_tool -change <libpython-name> <path-to-libpython-in-virtual-env> target/debug/metta-repl
```
This must be redone each time the repl is rebuilt, e.g. with `cargo build`.

##### Set the `DYLD_FALLBACK_LIBRARY_PATH` environment variable prior to launching `metta-repl`
```
export DYLD_FALLBACK_LIBRARY_PATH=<path-to-libpython-directory-in-virtual-env>
```
This can be done in your `~/.bashrc` file if you don't want to do it each time you launch the REPL.

For more information about linking `libpython`, see [#432](https://github.com/trueagi-io/hyperon-experimental/issues/432).

# Development

## Structure of the codebase
Expand Down
8 changes: 0 additions & 8 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ enable_testing()
option(BUILD_SHARED_LIBS "Build shared library" ON)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)

execute_process(
# --build is required to build dependencies from source under cibuildwheel
# environment
COMMAND cmake -E env CC= CXX= conan install --build -pr:b default -pr:h default -- ${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
include(${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

# HYPERONC_TARGET_DIR is used as a target dir for cargo. Cargo automatically adds
# `debug/release` suffix to the value of --target-dir argument so we need to
# calculate actual path to compiled library using $<CONFIG:...> cmake generator
Expand Down
6 changes: 5 additions & 1 deletion c/conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
libcheck/0.15.2

[generators]
cmake
CMakeDeps
CMakeToolchain

[options]
libcheck/*:with_subunit=False
12 changes: 7 additions & 5 deletions c/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
find_package(check REQUIRED)

set(TEST_SOURCES
test.c
int_gnd.c
Expand All @@ -6,21 +8,21 @@ set(TEST_SOURCES
)

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

add_executable(check_space check_space.c ${TEST_SOURCES})
target_link_libraries(check_space hyperonc-shared CONAN_PKG::libcheck)
target_link_libraries(check_space hyperonc-shared Check::check)
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-shared CONAN_PKG::libcheck)
target_link_libraries(check_sexpr_parser hyperonc-shared Check::check)
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-shared CONAN_PKG::libcheck)
target_link_libraries(check_types hyperonc-shared Check::check)
add_test(NAME check_types COMMAND check_types)

add_executable(check_runner check_runner.c ${TEST_SOURCES})
target_link_libraries(check_runner hyperonc-shared CONAN_PKG::libcheck)
target_link_libraries(check_runner hyperonc-shared Check::check)
add_test(NAME check_runner COMMAND check_runner)
Loading

0 comments on commit d4774ff

Please sign in to comment.