gemini-code-assist[bot] commented on code in PR #254:
URL: https://github.com/apache/tvm-ffi/pull/254#discussion_r2512328147
##########
addons/tvm-ffi-orcjit/CMakeLists.txt:
##########
@@ -0,0 +1,114 @@
+cmake_minimum_required(VERSION 3.18)
+project(
+ tvm_ffi_orcjit
+ VERSION 0.1.0
+ LANGUAGES C CXX
+)
+
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+
+# Find dependencies
+find_package(LLVM REQUIRED CONFIG)
+message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
+message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
+
+# Add LLVM definitions and include directories early
+separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
+add_definitions(${LLVM_DEFINITIONS_LIST})
+include_directories(${LLVM_INCLUDE_DIRS})
+
+# Find tvm-ffi Look for tvm-ffi in the parent repository first, then system
+set(TVM_FFI_ROOT
+ "${CMAKE_CURRENT_SOURCE_DIR}/../.."
+ CACHE PATH "Path to tvm-ffi"
+)
+
+if (EXISTS "${TVM_FFI_ROOT}/include/tvm/ffi/c_api.h")
+ message(STATUS "Using tvm-ffi from: ${TVM_FFI_ROOT}")
+
+ # Determine the library extension based on platform
+ if (APPLE)
+ set(TVM_FFI_LIB_EXT "dylib")
+ elseif (WIN32)
+ set(TVM_FFI_LIB_EXT "dll")
+ else ()
+ set(TVM_FFI_LIB_EXT "so")
+ endif ()
+
+ # Create imported target for tvm_ffi
+ add_library(tvm_ffi SHARED IMPORTED)
+ set_target_properties(
+ tvm_ffi
+ PROPERTIES IMPORTED_LOCATION
"${TVM_FFI_ROOT}/build/lib/libtvm_ffi.${TVM_FFI_LIB_EXT}"
+ INTERFACE_INCLUDE_DIRECTORIES
+
"${TVM_FFI_ROOT}/include;${TVM_FFI_ROOT}/3rdparty/dlpack/include"
+ )
+
+ # Set include directories (including src for internal headers)
+ include_directories(${TVM_FFI_ROOT}/include)
+ include_directories(${TVM_FFI_ROOT}/src)
+ include_directories(${TVM_FFI_ROOT}/3rdparty/dlpack/include)
+else ()
+ message(STATUS "Looking for system tvm-ffi")
+ find_package(tvm-ffi REQUIRED CONFIG)
+endif ()
+
+# LLVM components needed for ORC JIT v2
+llvm_map_components_to_libnames(LLVM_LIBS Core OrcJIT Support native)
+
+# Filter out non-existent targets
+set(LLVM_LIBS_FILTERED)
+foreach (lib ${LLVM_LIBS})
+ if (TARGET ${lib})
+ list(APPEND LLVM_LIBS_FILTERED ${lib})
+ else ()
+ message(STATUS "Skipping non-existent LLVM target: ${lib}")
+ endif ()
+endforeach ()
+set(LLVM_LIBS ${LLVM_LIBS_FILTERED})
+
+# Source files
+set(SOURCES src/ffi/orcjit_session.cc src/ffi/orcjit_dylib.cc)
+
+# Build shared library
+add_library(tvm_ffi_orcjit SHARED ${SOURCES})
+
+target_include_directories(
+ tvm_ffi_orcjit
+ PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
+ PRIVATE ${LLVM_INCLUDE_DIRS}
+)
+
+target_link_libraries(
+ tvm_ffi_orcjit
+ PUBLIC tvm_ffi
+ PRIVATE LLVM
Review Comment:

The `find_package(LLVM ... CONFIG)` command does not create a single `LLVM`
target. Instead, `llvm_map_components_to_libnames` populates the `LLVM_LIBS`
variable with a list of component library targets. You should link against
`${LLVM_LIBS}`.
```
PRIVATE ${LLVM_LIBS}
```
##########
addons/tvm-ffi-orcjit/CMakeLists.txt:
##########
@@ -0,0 +1,114 @@
+cmake_minimum_required(VERSION 3.18)
+project(
+ tvm_ffi_orcjit
+ VERSION 0.1.0
+ LANGUAGES C CXX
+)
+
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+
+# Find dependencies
+find_package(LLVM REQUIRED CONFIG)
+message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
+message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
+
+# Add LLVM definitions and include directories early
+separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
+add_definitions(${LLVM_DEFINITIONS_LIST})
Review Comment:

These `add_definitions` are redundant as `target_compile_definitions` is
used for the `tvm_ffi_orcjit` target on line 93. It's better to use
`target_compile_definitions` for target-specific definitions. I suggest
removing these lines to avoid redundancy.
##########
addons/tvm-ffi-orcjit/README.md:
##########
@@ -0,0 +1,230 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements. See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership. The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License. You may obtain a copy of the License at -->
+
+<!--- http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied. See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+# TVM-FFI OrcJIT
+
+A Python package that enables dynamic loading of TVM-FFI exported object files
(`.o`) using LLVM ORC JIT v2.
+
+## Features
+
+- **Dynamic Loading**: Load compiled object files at runtime using LLVM's ORC
JIT v2
+- **Incremental Loading**: Add multiple object files to the same loader
instance
+- **TVM-FFI Integration**: Seamlessly works with TVM-FFI's stable C ABI
+- **Python API**: Simple Pythonic interface for loading and calling compiled
functions
+- **Standalone Package**: Works alongside apache-tvm-ffi without conflicts
+
+## Installation
+
+### Prerequisites
+
+- Python 3.8+
+- CMake 3.18+
+- LLVM 14+ (with ORC JIT support)
+- Ninja build system (recommended)
+
+### Build from Source
+
+1. Clone the repository with submodules:
+
+```bash
+git clone --recursive https://github.com/apache/tvm-ffi.git
+cd tvm-ffi/addons/tvm-ffi-orcjit
+```
+
+1. Build TVM-FFI dependency (from the root of tvm-ffi repository):
+
+```bash
+cd ../.. # Go to tvm-ffi root
+mkdir -p build && cd build
+cmake .. -G Ninja
+ninja
+cd addons/tvm-ffi-orcjit
+```
+
+1. Create build directory and configure with CMake:
+
+```bash
+mkdir -p build
+cd build
+cmake .. \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
+ -G Ninja
+```
+
+1. Build the project:
+
+```bash
+cmake --build . -j$(nproc)
+cd ..
+```
+
+The shared library will be created at: `build/libtvm_ffi_orcjit.so`
+
+1. Install the Python package:
+
+```bash
+# Using pip
+pip install .
+
+# Or for development (editable install)
+pip install -e .
+```
+
+## Usage
+
+### Basic Example
+
+```python
+from tvm_ffi_orcjit import ObjectLoader
+
+# Create a loader instance
+loader = ObjectLoader()
+
+# Load an object file
+loader.load("example.o")
+
+# Get and call a function
+add_func = loader.get_function("simple_add")
+result = add_func(1, 2)
+print(f"Result: {result}") # Output: Result: 3
+```
+
+### Incremental Loading
+
+Load multiple object files and access functions from all of them:
+
+```python
+from tvm_ffi_orcjit import ObjectLoader
+
+loader = ObjectLoader()
+
+# Load first object file
+loader.load("math_ops.o")
+add = loader.get_function("simple_add")
+
+# Load second object file - functions from first remain accessible
+loader.load("string_ops.o")
+concat = loader.get_function("string_concat")
+
+# Both functions work
+print(add(10, 20)) # From math_ops.o
+print(concat("Hello", "World")) # From string_ops.o
+```
Review Comment:

The usage examples in this README appear to be outdated. They refer to an
`ObjectLoader` class which is not present in the current implementation. The
correct API, as demonstrated in `examples/quick-start/run.py`, uses
`create_session`, `session.create_library`, and `lib.add()`. Please update the
examples to reflect the current API to avoid confusion for new users.
##########
addons/tvm-ffi-orcjit/pyproject.toml:
##########
@@ -0,0 +1,55 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+[build-system]
+requires = ["scikit-build-core>=0.3.3", "pybind11"]
Review Comment:

The `pybind11` package is listed as a build-time requirement, but it doesn't
appear to be used in this project. The FFI is handled by `tvm-ffi`'s reflection
mechanism. You can likely remove this dependency.
```suggestion
requires = ["scikit-build-core>=0.3.3"]
```
##########
addons/tvm-ffi-orcjit/examples/quick-start/compile.sh:
##########
@@ -0,0 +1,60 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Compile script for quick-start example
+
+set -e
+
+# Colors for output
+GREEN='\\033[0;32m'
+RED='\\033[0;31m'
+NC='\\033[0m' # No Color
+
+echo -e "${GREEN}Compiling add.cc to object file...${NC}"
+
+# Check if tvm-ffi-config is available
+if ! command -v tvm-ffi-config &> /dev/null; then
+ echo -e "${RED}Error: tvm-ffi-config not found${NC}"
+ echo "Make sure apache-tvm-ffi is installed:"
+ echo " pip install -e ../../3rdparty/tvm-ffi"
Review Comment:

The path in this `pip install` command seems incorrect. From the
`examples/quick-start` directory, the project root is three levels up. The path
should be `../../../`.
```suggestion
echo " pip install -e ../../../"
```
##########
addons/tvm-ffi-orcjit/README.md:
##########
@@ -0,0 +1,230 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements. See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership. The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License. You may obtain a copy of the License at -->
+
+<!--- http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied. See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+# TVM-FFI OrcJIT
+
+A Python package that enables dynamic loading of TVM-FFI exported object files
(`.o`) using LLVM ORC JIT v2.
+
+## Features
+
+- **Dynamic Loading**: Load compiled object files at runtime using LLVM's ORC
JIT v2
+- **Incremental Loading**: Add multiple object files to the same loader
instance
+- **TVM-FFI Integration**: Seamlessly works with TVM-FFI's stable C ABI
+- **Python API**: Simple Pythonic interface for loading and calling compiled
functions
+- **Standalone Package**: Works alongside apache-tvm-ffi without conflicts
+
+## Installation
+
+### Prerequisites
+
+- Python 3.8+
+- CMake 3.18+
+- LLVM 14+ (with ORC JIT support)
+- Ninja build system (recommended)
+
+### Build from Source
+
+1. Clone the repository with submodules:
+
+```bash
+git clone --recursive https://github.com/apache/tvm-ffi.git
+cd tvm-ffi/addons/tvm-ffi-orcjit
+```
+
+1. Build TVM-FFI dependency (from the root of tvm-ffi repository):
+
+```bash
+cd ../.. # Go to tvm-ffi root
+mkdir -p build && cd build
+cmake .. -G Ninja
+ninja
+cd addons/tvm-ffi-orcjit
+```
+
+1. Create build directory and configure with CMake:
+
+```bash
+mkdir -p build
+cd build
+cmake .. \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
+ -G Ninja
+```
+
+1. Build the project:
+
+```bash
+cmake --build . -j$(nproc)
+cd ..
+```
+
+The shared library will be created at: `build/libtvm_ffi_orcjit.so`
+
+1. Install the Python package:
+
+```bash
+# Using pip
+pip install .
+
+# Or for development (editable install)
+pip install -e .
+```
+
+## Usage
+
+### Basic Example
+
+```python
+from tvm_ffi_orcjit import ObjectLoader
+
+# Create a loader instance
+loader = ObjectLoader()
+
+# Load an object file
+loader.load("example.o")
+
+# Get and call a function
+add_func = loader.get_function("simple_add")
+result = add_func(1, 2)
+print(f"Result: {result}") # Output: Result: 3
+```
+
+### Incremental Loading
+
+Load multiple object files and access functions from all of them:
+
+```python
+from tvm_ffi_orcjit import ObjectLoader
+
+loader = ObjectLoader()
+
+# Load first object file
+loader.load("math_ops.o")
+add = loader.get_function("simple_add")
+
+# Load second object file - functions from first remain accessible
+loader.load("string_ops.o")
+concat = loader.get_function("string_concat")
+
+# Both functions work
+print(add(10, 20)) # From math_ops.o
+print(concat("Hello", "World")) # From string_ops.o
+```
+
+### Direct Module Access
+
+You can also use TVM-FFI's `load_module` directly (`.o` files are
automatically handled):
+
+```python
+import tvm_ffi
+
+# Load object file as a module
+module = tvm_ffi.load_module("example.o")
+
+# Get function
+func = module.get_function("my_function")
+result = func(arg1, arg2)
+```
+
+## How It Works
+
+1. **C++ Backend**: The package implements a `Library` subclass using LLVM's
ORC JIT v2 (`LLJIT`)
+2. **Registration**: Registers with TVM-FFI as a loader for `.o` files via
`ffi.Module.load_from_file.o`
+3. **Symbol Resolution**: Uses LLJIT's `lookup()` to resolve TVM-FFI exported
symbols
+4. **Module Integration**: Wraps the ORC JIT library in `LibraryModuleObj` for
seamless TVM-FFI integration
+
+## Development
+
+### Building with CMake
+
+```bash
+mkdir build && cd build
+cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
+cmake --build .
+```
+
+### Project Structure
+
+```text
+tvm-ffi-orcjit/
+├── CMakeLists.txt # CMake build configuration
+├── pyproject.toml # Python package metadata
+├── README.md # This file
+├── example.py # Usage example
+├── include/
+│ └── tvm/ffi/orcjit/
+│ └── orcjit_library.h # C++ header
+├── src/
+│ └── ffi/
+│ └── orcjit_library.cc # C++ implementation
+└── python/
+ └── tvm_ffi_orcjit/
+ ├── __init__.py # Module exports
+ └── loader.py # Python ObjectLoader class
Review Comment:

The project structure describes a `loader.py` file, but the implementation
uses `session.py` and `dylib.py`. Please update the project structure diagram
to accurately reflect the files in the package.
```suggestion
└── session.py # Python ExecutionSession class
└── dylib.py # Python DynamicLibrary class
```
##########
addons/tvm-ffi-orcjit/README.md:
##########
@@ -0,0 +1,230 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements. See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership. The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License. You may obtain a copy of the License at -->
+
+<!--- http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied. See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+# TVM-FFI OrcJIT
+
+A Python package that enables dynamic loading of TVM-FFI exported object files
(`.o`) using LLVM ORC JIT v2.
+
+## Features
+
+- **Dynamic Loading**: Load compiled object files at runtime using LLVM's ORC
JIT v2
+- **Incremental Loading**: Add multiple object files to the same loader
instance
+- **TVM-FFI Integration**: Seamlessly works with TVM-FFI's stable C ABI
+- **Python API**: Simple Pythonic interface for loading and calling compiled
functions
+- **Standalone Package**: Works alongside apache-tvm-ffi without conflicts
+
+## Installation
+
+### Prerequisites
+
+- Python 3.8+
+- CMake 3.18+
+- LLVM 14+ (with ORC JIT support)
+- Ninja build system (recommended)
+
+### Build from Source
+
+1. Clone the repository with submodules:
+
+```bash
+git clone --recursive https://github.com/apache/tvm-ffi.git
+cd tvm-ffi/addons/tvm-ffi-orcjit
+```
+
+1. Build TVM-FFI dependency (from the root of tvm-ffi repository):
+
+```bash
+cd ../.. # Go to tvm-ffi root
+mkdir -p build && cd build
+cmake .. -G Ninja
+ninja
+cd addons/tvm-ffi-orcjit
+```
+
+1. Create build directory and configure with CMake:
+
+```bash
+mkdir -p build
+cd build
+cmake .. \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
+ -G Ninja
+```
+
+1. Build the project:
+
+```bash
+cmake --build . -j$(nproc)
+cd ..
+```
+
+The shared library will be created at: `build/libtvm_ffi_orcjit.so`
+
+1. Install the Python package:
+
+```bash
+# Using pip
+pip install .
+
+# Or for development (editable install)
+pip install -e .
+```
+
+## Usage
+
+### Basic Example
+
+```python
+from tvm_ffi_orcjit import ObjectLoader
+
+# Create a loader instance
+loader = ObjectLoader()
+
+# Load an object file
+loader.load("example.o")
+
+# Get and call a function
+add_func = loader.get_function("simple_add")
+result = add_func(1, 2)
+print(f"Result: {result}") # Output: Result: 3
+```
+
+### Incremental Loading
+
+Load multiple object files and access functions from all of them:
+
+```python
+from tvm_ffi_orcjit import ObjectLoader
+
+loader = ObjectLoader()
+
+# Load first object file
+loader.load("math_ops.o")
+add = loader.get_function("simple_add")
+
+# Load second object file - functions from first remain accessible
+loader.load("string_ops.o")
+concat = loader.get_function("string_concat")
+
+# Both functions work
+print(add(10, 20)) # From math_ops.o
+print(concat("Hello", "World")) # From string_ops.o
+```
+
+### Direct Module Access
+
+You can also use TVM-FFI's `load_module` directly (`.o` files are
automatically handled):
+
+```python
+import tvm_ffi
+
+# Load object file as a module
+module = tvm_ffi.load_module("example.o")
+
+# Get function
+func = module.get_function("my_function")
+result = func(arg1, arg2)
+```
Review Comment:

This section on "Direct Module Access" suggests that
`tvm_ffi.load_module("example.o")` is supported. However, the implementation
does not seem to register a module loader for `.o` files. If this feature is
not yet implemented, it would be best to remove this section or clearly mark it
as a future capability to prevent user confusion.
##########
addons/tvm-ffi-orcjit/python/tvm_ffi_orcjit/dylib.py:
##########
@@ -0,0 +1,133 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""ORC JIT Dynamic Library."""
+
+from __future__ import annotations
+
+from pathlib import Path
+from typing import TYPE_CHECKING, Any
+
+from tvm_ffi import Function, get_global_func
+from tvm_ffi._ffi_api import ModuleGetFunction
+
+if TYPE_CHECKING:
+ from .session import ExecutionSession
+
+
+class DynamicLibrary:
+ """ORC JIT Dynamic Library (JITDylib).
+
+ Represents a collection of symbols that can be loaded from object files
and linked
+ against other dynamic libraries. Supports JIT compilation and symbol
resolution.
+
+ Examples
+ --------
+ >>> session = create_session()
+ >>> lib = session.create_library()
+ >>> lib.add("add.o")
+ >>> lib.add("multiply.o")
+ >>> add_func = lib.get_function("add")
+ >>> result = add_func(1, 2)
+
+ """
+
+ def __init__(self, handle: Any, session: ExecutionSession) -> None:
+ """Initialize DynamicLibrary from a handle.
+
+ Parameters
+ ----------
+ handle : object
+ The underlying C++ ORCJITDynamicLibrary object.
+ session : ExecutionSession
+ The parent execution session (kept alive for the library's
lifetime).
+
+ """
+ self._handle = handle
+ self._session = session # Keep session alive
+ self._add_func = get_global_func("orcjit.DynamicLibraryAdd")
+ self._link_func = get_global_func("orcjit.DynamicLibraryLinkAgainst")
+ self._to_module_func = get_global_func("orcjit.DynamicLibraryToModule")
+
+ def add(self, object_file: str | Path) -> None:
+ """Add an object file to this dynamic library.
+
+ Parameters
+ ----------
+ object_file : str or Path
+ Path to the object file to load.
+
+ Examples
+ --------
+ >>> lib.add("add.o")
+ >>> lib.add(Path("multiply.o"))
+
+ """
+ if isinstance(object_file, Path):
+ object_file = str(object_file)
+ self._add_func(self._handle, object_file)
+
+ def link_against(self, *libraries: DynamicLibrary) -> None:
+ """Link this library against other dynamic libraries.
+
+ Sets the search order for symbol resolution. Symbols not found in this
library
+ will be searched in the linked libraries in the order specified.
+
+ Parameters
+ ----------
+ *libraries : DynamicLibrary
+ One or more dynamic libraries to link against.
+
+ Examples
+ --------
+ >>> session = create_session()
+ >>> lib_utils = session.create_library()
+ >>> lib_utils.add("utils.o")
+ >>> lib_main = session.create_library()
+ >>> lib_main.add("main.o")
+ >>> lib_main.link_against(lib_utils) # main can call utils symbols
+
+ """
+ handles = [lib._handle for lib in libraries]
+ self._link_func(self._handle, *handles)
Review Comment:

The `link_against` method accepts `*libraries`, which implies it can link
against multiple libraries. However, the C++ backend function
`orcjit.DynamicLibraryLinkAgainst` only supports linking against a single
library at a time. This will cause a `TypeError` if more than one library is
passed.
To fix this, you should either update the Python method to accept only one
library or modify the C++ backend to handle multiple libraries. Given the
current C++ implementation, changing the Python API is the most direct solution.
```python
def link_against(self, library: DynamicLibrary) -> None:
"""Link this library against another dynamic library.
Sets the search order for symbol resolution. Symbols not found in
this library
will be searched in the linked library.
Parameters
----------
library : DynamicLibrary
The dynamic library to link against.
Examples
--------
>>> session = create_session()
>>> lib_utils = session.create_library()
>>> lib_utils.add("utils.o")
>>> lib_main = session.create_library()
>>> lib_main.add("main.o")
>>> lib_main.link_against(lib_utils) # main can call utils symbols
"""
self._link_func(self._handle, library._handle)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]