Improve compatibility of build_rust
with build_ext
#28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rationale
The behaviour of
build_ext
is the following: when generating compilationartifacts (such as
.o
files), it will put them in a directory defined by thebuild_temp
argument, and within that directory create a directory named afterthe project name in
setup.py
, and them dump its temporary files there.The only way to do that with
build_rust
was through editing theCARGO_TARGET_DIR
environment variable, but this is not practical and also doesnot comply well with the different available configuration files (
setup.cfg
,user
distutils.cfg
and the like).Implementation
--build-temp
argument to the CLI, or setsbuild_temp
within the
[build]
,[build_ext]
or[build_rust]
sections of anyconfiguration file, then cargo will use that directory as a target directory.
build_temp
(which isbuild/temp.<platform>-<version>
).CARGO_TARGET_DIR
is set, then it will overwrite any python-defined settingand build to that directory directly.
I also made
build_rust
inherit frombuild_ext
the following options:inplace
and
debug
.Perks
Cargo.toml
files indifferent subdirectories, cargo would create a local target directory for each
library, and thus rebuild several times the same cargo modules (for instance,
PyO3
!)clean_rust
command, sincepython setup.py clean
removes the
build_temp
directorysetup.cfg
defined options #27 😉CARGO_TARGET_DIR
is set, and multiple extensions are built for a project, the wrong library can be copied (sincebuild_rust
did not check for the library name beforehand)Drawbacks