@@ -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,45 @@ 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+ ```
224+ $ PYOXIDIZER_EXECUTABLE=$HOME/.cargo/bin/pyoxidizer \
225+ PYO3_PYTHON=$HOME/python/install/bin/python3.9 \
226+ PYOXIDIZER_CONFIG=$(pwd)/pyoxidizer.bzl \
227+ TARGET=x86_64-apple-darwin \
228+ CARGO_MANIFEST_DIR=. \
229+ OUT_DIR=target/out \
230+ PROFILE=debug \
231+ pyoxidizer run-build-script build.rs
232+ ```
233+
234+ That will put the artifacts in target/out.
235+
236+ Then you can run cargo to build your crate:
237+
238+ ```
239+ $ PYOXIDIZER_REUSE_ARTIFACTS=1 \
240+ PYOXIDIZER_ARTIFACT_DIR=$(pwd)/target/out \
241+ PYOXIDIZER_EXECUTABLE=$HOME/.cargo/bin/pyoxidizer \
242+ PYOXIDIZER_CONFIG=$(pwd)/pyoxidizer.bzl \
243+ PYO3_CONFIG_FILE=$(pwd)/target/out/pyo3-build-config-file.txt cargo \
244+ build --no-default-features --features \
245+ "build-mode-prebuilt-artifacts global-allocator-jemalloc allocator-jemalloc"
246+ ```
247+
248+ After building, you should find an executable in target/debug/.
249+
250+ Note that currently this does not produce any files that have been redirected to the filesystem,
251+ such as extension modules. For now you'll need to copy them in from a normal pyoxidizer run, or
252+ see https://github.com/indygreg/PyOxidizer/pull/466
253+
254+ On Windows, the paths will need updating, and the jemalloc features will need to be removed.
255+
256+ If you wish to dig further into how PyOxidizer builds projects, project_building.rs
257+ is a good place to start.
0 commit comments