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

[c++/python] Build flow improvements #496

Merged
merged 11 commits into from
Nov 7, 2022

Conversation

gspowley
Copy link
Member

@gspowley gspowley commented Nov 1, 2022

A number of build flow improvements based on developer feedback:

  1. Document a reliable way to build tiledbsoma, including after pulling the latest source code.
  2. Add a developer Makefile to automate build commands.
  3. Add more documentation on components of build flow (see libtiledbsoma/README.md).
  4. Provide a way to build only a libtiledbsoma static library for R.
  5. Merge C++ tests into Python CI to reduce redundant CI runs.

Example C++ dev commands:

# setup python virtual env
python -m venv test/tiledbsoma
source test/tiledbsoma/bin/activate

# install developer requirements
pip install -r apis/python/requirements_dev.txt

# install and test tiledbsoma
make install test

R build command:

# requires cmake >= 3.21
make r-build

@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #22584: Some centralization of R/C++ and Python/C++ builds.

@gspowley gspowley force-pushed the gspowley/sc-22584/build-flow-improvements branch from 895e5ee to bfdfd22 Compare November 1, 2022 20:18
@gspowley gspowley force-pushed the gspowley/sc-22584/build-flow-improvements branch from bfdfd22 to 4ba0d1e Compare November 1, 2022 22:58
@gspowley gspowley marked this pull request as ready for review November 1, 2022 23:25
@eddelbuettel
Copy link
Contributor

Looks fabulous at a first glance. Will test-drive after dinner. Love the Makefile which I find easier to read / scan / understand that the verbosity of 'that other flavor'.

@@ -1,6 +1,9 @@
import pyarrow as pa
from typeguard.importhook import install_import_hook

# avoid typeguard by importing before calling install_import_hook
Copy link
Member

Choose a reason for hiding this comment

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

❤️

cd TileDB-SOMA
```
---
## Setup a Python Virtual Environment
Copy link
Member

Choose a reason for hiding this comment

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

nit: Set up a ...


Remove old build files:
---
## Python Only Development
Copy link
Member

Choose a reason for hiding this comment

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

nit: Python-only Development

Comment on lines -11 to -19
BUILD_TYPE=${1:-Release} # default to Release build
if [ ! -z "$LIBTILEDBSOMA_DEBUG_BUILD" ]; then
echo
echo ================================================================
echo LIBTILEDBSOMA SCRIPTS/BLD BUILD_TYPE ${BUILD_TYPE}
echo ================================================================
else
echo "Building ${BUILD_TYPE} build"
fi
Copy link
Member

Choose a reason for hiding this comment

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

I found the output from this verbose setup far easier to parse -- while it lasted. :(

👋 ✌️ 🖖

Copy link
Member Author

Choose a reason for hiding this comment

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

I found all of the debug messages made the code harder to modify/maintain.

Copy link
Member

Choose a reason for hiding this comment

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

@gspowley which I knew would happen hence 🖖


# - incrementally compile and install the c++ code
# - copy the shared objects on top of the python dev build
.PHONY: update
Copy link
Member

Choose a reason for hiding this comment

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

Linux error:

$ make update
make[1]: /tmp/pip-build-env-imfu1ozp/overlay/local/lib/python3.10/dist-packages/cmake/data/bin/cmake: No such file or directory
make[1]: *** [Makefile:180: cmake_check_build_system] Error 127
make: *** [Makefile:9: update] Error 2

MacOS error:

johnkerl@Kerl-MBP[prod][gspowley/sc-22584/build-flow-improvements][TileDB-SOMA]$ make update
[ 50%] Built target ep_spdlog
[ 56%] Performing configure step for 'libtiledbsoma'
-- Using default install prefix /Users/johnkerl/git/single-cell-data/TileDB-SOMA/dist. To control CMAKE_INSTALL_PREFIX, set OVERRIDE_INSTALL_PREFIX=OFF
-- Install prefix is /Users/johnkerl/git/single-cell-data/TileDB-SOMA/dist.
-- Skipping search for TileDB, building it as an external project. To use system TileDB, set FORCE_BUILD_TILEDB=OFF
-- Starting TileDB-SOMA regular build.
-- Performing Test HAVE_AVX2
-- Performing Test HAVE_AVX2 - Success
-- Starting TileDB-SOMA build.
-- Found TileDB: TILEDB_LIB-NOTFOUND
-- Building with commit hash 4ba0d1e
CMake Warning at src/CMakeLists.txt:57 (message):
  Building TileDB without deprecation warnings


CMake Error at src/pyapi/CMakeLists.txt:3 (find_package):
  Could not find a package configuration file provided by "pybind11" with any
  of the following names:

    pybind11Config.cmake
    pybind11-config.cmake

  Add the installation prefix of "pybind11" to CMAKE_PREFIX_PATH or set
  "pybind11_DIR" to a directory containing one of the above files.  If
  "pybind11" provides a separate development package or SDK, be sure it has
  been installed.


-- Configuring incomplete, errors occurred!
See also "/Users/johnkerl/git/single-cell-data/TileDB-SOMA/build/libtiledbsoma/CMakeFiles/CMakeOutput.log".
See also "/Users/johnkerl/git/single-cell-data/TileDB-SOMA/build/libtiledbsoma/CMakeFiles/CMakeError.log".
make[3]: *** [libtiledbsoma-prefix/src/libtiledbsoma-stamp/libtiledbsoma-configure] Error 1
make[2]: *** [CMakeFiles/libtiledbsoma.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [update] Error 2

Note this happened on MacOS even after pip install -r apis/python/requirements_dev.txt

Copy link
Member Author

Choose a reason for hiding this comment

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

make[1]: /tmp/pip-build-env-imfu1ozp/overlay/local/lib/python3.10/dist-packages/cmake/data/bin/cmake: No such file or directory
make[1]: *** [Makefile:180: cmake_check_build_system] Error 127
make: *** [Makefile:9: update] Error 2

The Linux error is definitely cause by running something like this (because I've seen this before):

pip install -e apis/python
make update

Here's what happens:

  1. pip install creates an overlay environment (/tmp/pip-build-env-imfu1ozp/overlay), where it install cmake and builds the code.
  2. make update tries to call the cmake from the overlay environment, but it is no longer there.

The MacOS error may be caused by the same sequence of commands.

The libtiledbsoma/README.md describes two dev modes (Python-only and Python and C++) and which build commands should be used in each.

Maybe we should have just one developer mode that uses the Makefile and avoid the confusion?

# - run the clean rule
# - build the c++ static library for r
.PHONY: r-build
r-build: clean
Copy link
Member

Choose a reason for hiding this comment

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

Makefile Outdated
# - run c++ unit tests
# - run pytests
.PHONY: test
test: test/soco
Copy link
Member

Choose a reason for hiding this comment

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

Makefile Outdated Show resolved Hide resolved
Copy link
Contributor

@eddelbuettel eddelbuettel left a comment

Choose a reason for hiding this comment

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

The make r-build target is close in that it gets the desired static library and the core headers -- but it misses the externals/ header directory we need for span under C++17.

@gspowley
Copy link
Member Author

gspowley commented Nov 2, 2022

The make r-build target is close in that it gets the desired static library and the core headers -- but it misses the externals/ header directory we need for span under C++17.

cmake >= 3.23 makes this easier to support. Does this install tree capture everything?

dist/
├── include
│   ├── externals
│   │   └── span
│   │       └── span.hpp
│   └── tiledbsoma
│       ├── array_buffers.h
│       ├── column_buffer.h
│       ├── common.h
│       ├── logger_public.h
│       ├── managed_query.h
│       ├── soma_reader.h
│       ├── tiledbsoma
│       ├── tiledbsoma_export.h
│       └── util.h
└── lib
    ├── libtiledb.so.2.12
    └── libtiledbsoma.a

@eddelbuettel
Copy link
Contributor

eddelbuettel commented Nov 2, 2022

Thanks, I noticed the change late last eve but I will need a newer cmake first to see and test. The image looks good (though strictly speaking I would want just the .a library). Also, can I give a DESTDIR to bld ?

Edit Sorry, it is also missing the two arrow headers we should move to a different directory. They are currently 'hiding' with the two Python headers but are not Python-specific. The R package needs them too.

Edit 2 Plus the thread_pool/ headers.

@eddelbuettel
Copy link
Contributor

eddelbuettel commented Nov 2, 2022

Iff the additional headers are added we can build, and link, and load. Note that in the what I quote below we now only compile the r-api source files (for now all starting with r namely rinterface.cpp, riterator.cpp and rutilities.cpp) plus the Rcpp-auto-generated glue RcppExports.cpp. We no longer compile the libtiledbsoma files, instead we link with libtiledbsoma.a.

And the R package does a full 'does it turn on?' test by trying to load at the penultimate step so this really is good.

(But I did have to add extra headers in directory thread_pool/ and pyapi. So we are close. We can see the cigar.)

edd@rob:~/git/tiledb-soma/apis/r(gspowley/sc-22584/build-flow-improvements)$ ./cleanup 
edd@rob:~/git/tiledb-soma/apis/r(gspowley/sc-22584/build-flow-improvements)$ install.r       # simple wrapper to R CMD INSTALL
* installing *source* package found in current working directory ...
* installing *source* package ‘tiledbsoma’ ...
** using staged installation
** updated src/Makevars for system library via pkg-config
** libs
ccache g++  -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I. -I../inst/include/ -I/usr/local/include -I/usr/local/lib/R/site-library/arch/include -DR_BUILD   -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppSpdlog/include' -I'/usr/local/lib/R/site-library/arch/include'    -fpic  -g -O3 -Wall -pipe -pedantic -Wno-ignored-attributes  -c RcppExports.cpp -o RcppExports.o
ccache g++  -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I. -I../inst/include/ -I/usr/local/include -I/usr/local/lib/R/site-library/arch/include -DR_BUILD   -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppSpdlog/include' -I'/usr/local/lib/R/site-library/arch/include'    -fpic  -g -O3 -Wall -pipe -pedantic -Wno-ignored-attributes  -c rinterface.cpp -o rinterface.o
ccache g++  -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I. -I../inst/include/ -I/usr/local/include -I/usr/local/lib/R/site-library/arch/include -DR_BUILD   -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppSpdlog/include' -I'/usr/local/lib/R/site-library/arch/include'    -fpic  -g -O3 -Wall -pipe -pedantic -Wno-ignored-attributes  -c riterator.cpp -o riterator.o
ccache g++  -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I. -I../inst/include/ -I/usr/local/include -I/usr/local/lib/R/site-library/arch/include -DR_BUILD   -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppSpdlog/include' -I'/usr/local/lib/R/site-library/arch/include'    -fpic  -g -O3 -Wall -pipe -pedantic -Wno-ignored-attributes  -c rutilities.cpp -o rutilities.o
ccache g++ -std=gnu++17 -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -o tiledbsoma.so RcppExports.o rinterface.o riterator.o rutilities.o -L/usr/local/lib -ltiledb libtiledbsoma.a -L/usr/lib/R/lib -lR
if [ "" != "Windows_NT" ] && [ `uname -s` = 'Darwin' ] && [ -f ../inst/tiledb/lib/libtiledb.dylib ] && [ -f tiledbsoma.so ]; then install_name_tool -change libz.1.dylib @rpath/libz.1.dylib ../inst/tiledb/lib/libtiledb.dylib; install_name_tool -add_rpath @loader_path/../tiledb/lib tiledbsoma.so; fi
installing to /usr/local/lib/R/site-library/00LOCK-r/00new/tiledbsoma/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (tiledbsoma)
edd@rob:~/git/tiledb-soma/apis/r(gspowley/sc-22584/build-flow-improvements)$ 

@gspowley gspowley force-pushed the gspowley/sc-22584/build-flow-improvements branch from d89e062 to 02a4b63 Compare November 7, 2022 15:50
Copy link
Contributor

@eddelbuettel eddelbuettel left a comment

Choose a reason for hiding this comment

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

Looks good to me, I should have some time this afternoon to check again on libtiledbsoma.a use and headers.

@eddelbuettel
Copy link
Contributor

Gave it another two spins to ascertain that

  1. It does not break the current use, which it passes (and which is of course what CI shows us)

  2. It does what it is supposed to do namely provide a libtiledbsoma.a plus headers we can use in apis/r and that passes too.

So 🚢 from me! Nice work.

@gspowley gspowley merged commit faa9021 into main Nov 7, 2022
@gspowley gspowley deleted the gspowley/sc-22584/build-flow-improvements branch November 7, 2022 21:40
@johnkerl johnkerl changed the title Build flow improvements [c++/python] Build flow improvements May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants