symforce-org / symforce

Fast symbolic computation, code generation, and nonlinear optimization for robotics
https://symforce.org
Apache License 2.0
1.41k stars 145 forks source link

Fix of pip install -e . on both macos and ubuntu #228

Closed bradley-solliday-skydio closed 2 years ago

bradley-solliday-skydio commented 2 years ago

This fixes the editable installation of symforce from source for setuptools>=64.0.0

This includes essentially two unrelated fixes.

The first is for cc_sym. The editable installation expects to find cc_sym in the top level of the symforce (I believe it's because setuptools finds the cc_sym shared library object in the top level of the source tree, which we have already been copying there from the build directory). However, the runpath of the cc_sym there still assumes the directory structure of the build directory that it was copied from. Hence, the loader can't find the dependencies (libsymforce_gen, libsymforce_opt, and libsymforce_cholesky).

To address this, I add the directory cc_sym is found in to its runpath (using $ORIGIN and @loader_path) and copy it's dependencies into it.

The second issue is that the editable installation expects the symengine package to use to be the one found in the source directory. However, that is missing the compiled symengine_wrapper shared library. To address this, I also copy it into the source directory.

For some reason the symengine_wrapper shared library file isn't always present in the symengine_install directory in the build directory (observed in on the github actions macos runner with python3.10), but it also seems to not always be needed. For that reason, if the copy fails, I tell the installation to just continue regardless.

Only performs these changes if build_ext.editable_install is True. Hence it requires setuptools>=64.0.0 (the version in which setuptools was made pep 660 compliant).

Tested using a github actions workflow.