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

Build helper functions for legate projects, legate-hello example #571

Merged
merged 26 commits into from
Mar 2, 2023

Conversation

jjwilke
Copy link

@jjwilke jjwilke commented Feb 15, 2023

With this set of helper functions, the CMakeLists.txt for a downstream project like cunumeric would now look like:

src/CMakeLists.txt:

add_library(hello
  hello_world.cc
  hello_world.h)
target_link_libraries(hello PRIVATE legate::core)
....

CMakeLists.txt:

cmake_minimum_required(VERSION 3.24.0 FATAL_ERROR)

project(hello VERSION 1.0 LANGUAGES C CXX)

find_package(legate_core REQUIRED)
legate_add_cpp_subdirectory(src hello EXPORT hello-export)
legate_add_cffi(${CMAKE_SOURCE_DIR}/src/hello_world.h)
legate_default_python_install(hello EXPORT hello-export)

@jjwilke jjwilke force-pushed the hello-world-boilerplate branch from 7d50b4a to ba8216e Compare February 15, 2023 03:35
@jjwilke
Copy link
Author

jjwilke commented Feb 15, 2023

Hello world example being developed here:

https://github.com/jjwilke/legate-hello-world

@jjwilke jjwilke changed the title Add helper functions to reduce build boilerplate for legate projects [WIP] Add helper functions to reduce build boilerplate for legate projects Feb 15, 2023
@jjwilke jjwilke added the category:improvement PR introduces an improvement and will be classified as such in release notes label Feb 15, 2023
@jjwilke jjwilke force-pushed the hello-world-boilerplate branch from d167004 to a08d963 Compare February 17, 2023 17:24
@trxcllnt
Copy link

@robertmaynard I'd also appreciate your thoughts on this PR.

@trxcllnt
Copy link

@jjwilke can we also add the LANGUAGES ${ENABLED_LANGUAGES} option to the rapids_export() calls in legate_core_{cpp,python}.cmake?

BUILD_EXPORT_SET ${OPT_EXPORT}
INSTALL_EXPORT_SET ${OPT_EXPORT})
if (NOT ${target}_FOUND)
add_subdirectory(${dir} ${CMAKE_SOURCE_DIR}/build)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use something like ${CMAKE_SOURCE_DIR}/legate_${${target}}_build instead of ${CMAKE_SOURCE_DIR}/build.

The build directory could already be used by a target named that, or a user might want to call legate_add_cpp_subdirectory multiple time and this wouldn't work

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robertmaynard that's actually the point of this line, since this is only executed when running via scikit-build

  1. If the user configures C++ independently, they can do it into ./build
  2. If the user lets scikit-build configure the C++ lib as a side-effect of building the Python lib, the C++ libs still end up in ./build (where normally they'd be under something like _skbuild/<arch>/cmake-build)

This stability helps with the runtime library loading we do when dev'ing locally w/ pip install --editable .

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I split the difference since it's a valid point that this only supports a single source directory. I put everything in:
${CMAKE_SOURCE_DIR}/build/legate_${target} - which I think is okay? @robertmaynard

This still makes the libraries easy to find.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjwilke that assumes users configuring the C++ library themselves know to build in that dir? my guess is they won't know to do this:

cmake -S . -B build/legate_hello_world && cmake --build build/legate_hello_world

CMAKE_ARGS="-Dhello_world_ROOT=$PWD/build/legate_hello_world" \
pip install --editable .

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should make it configurable, or do something like build/${cmake_build_type}? So that way at least it's build/Debug and build/Release?

Copy link

@robertmaynard robertmaynard Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using add_subdirectory(${dir} ${CMAKE_SOURCE_DIR}/build) you are stating that CMake should parse the CMakeLists.txt in ${dir} and place any build information in ${CMAKE_SOURCE_DIR}/build. This has the following issues:

  1. You are placing build artifacts in the soure tree. The path should start with CMAKE_BUILD_DIR.
    Since legate_add_cpp_subdirectory is executed by the users project we have no idea what source tree layout they have and shouldn't try to write to CMAKE_SOURCE_DIR.
  2. The second argument must be unique across a CMake project. So ${CMAKE_BUILD_DIR}/legate_${target} would be sufficient. So the following logic doesn't work currently:
legate_add_cpp_subdirectory(legate_plugin1 hello EXPORT hello-export)
legate_add_cpp_subdirectory(legate_plugin2 world EXPORT world-export)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks all for the suggestions. Silly mistakes on my part. I believe the latest version correctly puts things into CMAKE_BINARY_DIR into unique folders.

PTAL. @robertmaynard @trxcllnt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated version looks good to me

@jjwilke jjwilke changed the title [WIP] Add helper functions to reduce build boilerplate for legate projects Add helper functions to reduce build boilerplate for legate projects Feb 20, 2023
@jjwilke jjwilke force-pushed the hello-world-boilerplate branch from 3afe257 to 4619de9 Compare February 27, 2023 19:27
@jjwilke
Copy link
Author

jjwilke commented Feb 27, 2023

@trxcllnt @manopapad Sorry everybody... PTAL. With the recent breakage due to PR #581 I decided the hello-world examples should really be maintained in the legate-core repo with build testing in CI to make sure things don't get broken.

The current setup abuses find_package to "find" Legate in its own build tree when legate_core_EXAMPLE_BUILD_TESTS is ON.

@manopapad manopapad changed the title Add helper functions to reduce build boilerplate for legate projects Build helper functions for legate projects, legate-hello example Feb 27, 2023
@jjwilke jjwilke force-pushed the hello-world-boilerplate branch from 9a2bd85 to 31eef52 Compare March 1, 2023 18:44
@jjwilke jjwilke merged commit 847ef92 into nv-legate:branch-23.03 Mar 2, 2023
manopapad pushed a commit that referenced this pull request Mar 5, 2025
* simplify README and move content to docs

* split users guide and api ref chapters

* missing comma

* add contact email
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:improvement PR introduces an improvement and will be classified as such in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants