@@ -164,10 +164,7 @@ interpreter use the ``snmalloc`` allocator.
164164Using Cargo With Generated Rust Projects
165165========================================
166166
167- Rust developers will probably want to use ``cargo `` instead of ``pyoxidizer ``
168- for building auto-generated Rust projects. This is supported, but behavior can
169- be very finicky.
170-
167+ Building from a Rust project is not turn-key like PyOxidizer is.
171168PyOxidizer has to do some non-conventional things to get Rust projects to
172169build in very specific ways. Commands like ``pyoxidizer build `` abstract
173170away all of this complexity for you.
@@ -216,3 +213,41 @@ file contains some commented out settings that may need to be set for some
216213configurations (e.g. the ``standalone_static `` Windows distributions). Please
217214consult this file if running into build errors when not building through
218215``pyoxidizer ``.
216+
217+ An Example and Further Reference
218+ ==================================
219+
220+ Starting from a project freshly created with ``pyoxidizer init-rust-project sample ``,
221+ you'll first need to generate the build artifacts::
222+
223+ $ PYOXIDIZER_EXECUTABLE=$HOME/.cargo/bin/pyoxidizer \
224+ PYO3_PYTHON=$HOME/python/install/bin/python3.9 \
225+ PYOXIDIZER_CONFIG=$(pwd)/pyoxidizer.bzl \
226+ TARGET=x86_64-apple-darwin \
227+ CARGO_MANIFEST_DIR=. \
228+ OUT_DIR=target/out \
229+ PROFILE=debug \
230+ pyoxidizer run-build-script build.rs
231+
232+ That will put the artifacts in target/out.
233+
234+ Then you can run cargo to build your crate::
235+
236+ $ PYOXIDIZER_REUSE_ARTIFACTS=1 \
237+ PYOXIDIZER_ARTIFACT_DIR=$(pwd)/target/out \
238+ PYOXIDIZER_EXECUTABLE=$HOME/.cargo/bin/pyoxidizer \
239+ PYOXIDIZER_CONFIG=$(pwd)/pyoxidizer.bzl \
240+ PYO3_CONFIG_FILE=$(pwd)/target/out/pyo3-build-config-file.txt cargo \
241+ build --no-default-features --features \
242+ "build-mode-prebuilt-artifacts global-allocator-jemalloc allocator-jemalloc"
243+
244+ After building, you should find an executable in target/debug/.
245+
246+ Note that currently this does not produce any files that have been redirected to the filesystem,
247+ such as extension modules. For now you'll need to copy them in from a normal pyoxidizer run, or
248+ see https://github.com/indygreg/PyOxidizer/pull/466
249+
250+ On Windows, the paths will need updating, and the jemalloc features will need to be removed.
251+
252+ If you wish to dig further into how PyOxidizer builds projects, project_building.rs
253+ is a good place to start.
0 commit comments