Skip to content

Commit

Permalink
Tutorial editable install fix (#610) (#613)
Browse files Browse the repository at this point in the history
* replace hello => @target@

* fix library paths for editable installs

* deconflict user and auto skbuild cmake args

* clean up rapids_export calls in project template

---------

Co-authored-by: Jeremy <[email protected]>
Co-authored-by: Mads R. B. Kristensen <[email protected]>
  • Loading branch information
3 people authored Mar 8, 2023
1 parent d3cc8af commit 8f5dd49
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
35 changes: 25 additions & 10 deletions cmake/legate_helper_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ function(legate_default_cpp_install target)
DESTINATION ${lib_dir}
EXPORT ${LEGATE_OPT_EXPORT})

set(final_code_block
"set(${target}_BUILD_LIBDIR ${CMAKE_BINARY_DIR}/legate_${target})"
)

rapids_export(
INSTALL ${target}
EXPORT_SET ${LEGATE_OPT_EXPORT}
GLOBAL_TARGETS ${target}
NAMESPACE legate::
LANGUAGES ${ENABLED_LANGUAGES}
)

# build export targets
Expand All @@ -51,6 +56,8 @@ function(legate_default_cpp_install target)
EXPORT_SET ${LEGATE_OPT_EXPORT}
GLOBAL_TARGETS ${target}
NAMESPACE legate::
FINAL_CODE_BLOCK final_code_block
LANGUAGES ${ENABLED_LANGUAGES}
)
endfunction()

Expand Down Expand Up @@ -90,7 +97,7 @@ def get_libpath():
}[platform.system()]

def find_lib(libdir):
target = f"libhello{so_ext}*"
target = f"lib@target@{so_ext}*"
search_path = Path(libdir)
matches = [m for m in search_path.rglob(target)]
if matches:
Expand Down Expand Up @@ -138,14 +145,19 @@ header: str = """
@ONLY
)

# cmake doesn't let you pipe the output of a
# custom command so you have to generate a script
# that writes to a file and THEN run that in a
# custom command
if (DEFINED ${target}_BUILD_LIBDIR)
# this must have been imported from an existing editable build
set(libdir ${${target}_BUILD_LIBDIR})
else()
# libraries are built in a common spot
set(libdir ${CMAKE_BINARY_DIR}/legate_${target})
message("libdir to binary dir")
endif()
add_custom_target("generate_install_info_py" ALL
COMMAND ${CMAKE_COMMAND}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-Dtarget=${target}
-Dlibdir=${libdir}
-P ${generate_script}
OUTPUT ${install_info_py}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down Expand Up @@ -229,6 +241,9 @@ function(legate_add_cpp_subdirectory dir)
if (NOT ${target}_FOUND)
add_subdirectory(${dir} ${CMAKE_BINARY_DIR}/legate_${target})
legate_default_cpp_install(${target} EXPORT ${LEGATE_OPT_EXPORT})
else()
# Make sure the libdir is visible to other functions
set(${target}_BUILD_LIBDIR "${${target}_BUILD_LIBDIR}" PARENT_SCOPE)
endif()
else()
add_subdirectory(${dir} ${CMAKE_BINARY_DIR}/legate_${target})
Expand Down Expand Up @@ -320,9 +335,9 @@ class Mapper : public legate::mapping::LegateMapper {
const legate::mapping::MachineQueryInterface* machine_;
};

static const char* const library_name = "hello";
static const char* const library_name = "@target@";

Legion::Logger log_hello("hello");
Legion::Logger log_@target@(library_name);

/*static*/ legate::TaskRegistrar& Registry::get_registrar()
{
Expand Down Expand Up @@ -392,16 +407,16 @@ class UserLibrary(Library):
return self.name

def get_shared_library(self) -> str:
from hello.install_info import libpath
from @target@.install_info import libpath
return os.path.join(libpath, f"lib@target@{self.get_library_extension()}")

def get_c_header(self) -> str:
from hello.install_info import header
from @target@.install_info import header

return header

def get_registration_callback(self) -> str:
return "hello_perform_registration"
return "@target@_perform_registration"

def get_resource_configuration(self) -> ResourceConfig:
assert self.shared_object is not None
Expand Down
5 changes: 4 additions & 1 deletion examples/hello/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
f"-Dlegate_core_ROOT:STRING={legate_dir}",
]

os.environ["SKBUILD_CONFIGURE_OPTIONS"] = " ".join(cmake_flags)
env_cmake_args = os.environ.get("CMAKE_ARGS")
if env_cmake_args is not None:
cmake_flags.append(env_cmake_args)
os.environ["CMAKE_ARGS"] = " ".join(cmake_flags)


setup(
Expand Down

0 comments on commit 8f5dd49

Please sign in to comment.