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

pyoxidizer: allow specifying an existing project crate #468

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 39 additions & 25 deletions pyoxidizer/src/project_building.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ pub fn build_executable_with_rust_project<'a>(
})
}

/// Build a Python executable using a temporary Rust project.
/// Build a Python executable using a temporary Rust project, or
/// the one specified by the PYOXIDIZER_CRATE_FOLDER env var.
///
/// Returns the binary data constituting the built executable.
pub fn build_python_executable<'a>(
Expand All @@ -380,30 +381,43 @@ pub fn build_python_executable<'a>(
opt_level: &str,
release: bool,
) -> Result<BuiltExecutable<'a>> {
let cargo_exe = env
.ensure_rust_toolchain(logger, Some(target_triple))
.context("resolving Rust toolchain")?
.cargo_exe;

let temp_dir = tempfile::Builder::new()
.prefix("pyoxidizer")
.tempdir()
.context("creating temp directory")?;

// Directory needs to have name of project.
let project_path = temp_dir.path().join(bin_name);
let build_path = temp_dir.path().join("build");
let artifacts_path = temp_dir.path().join("artifacts");

initialize_project(
&env.pyoxidizer_source,
&project_path,
&cargo_exe,
None,
&[],
exe.windows_subsystem(),
)
.context("initializing project")?;
let temp_dir: tempfile::TempDir;
let project_path: PathBuf;

// Existing Rust project provided?
let root = if let Ok(folder) = std::env::var("PYOXIDIZER_CRATE_FOLDER") {
project_path = PathBuf::from(folder);
&project_path
} else {
// No existing project, we'll need to create a temporary one.
let cargo_exe = env
.ensure_rust_toolchain(logger, Some(target_triple))
.context("resolving Rust toolchain")?
.cargo_exe;

temp_dir = tempfile::Builder::new()
.prefix("pyoxidizer")
.tempdir()
.context("creating temp directory")?;

// Directory needs to have name of project.
project_path = temp_dir.path().join(bin_name);

initialize_project(
&env.pyoxidizer_source,
&project_path,
&cargo_exe,
None,
&[],
exe.windows_subsystem(),
)
.context("initializing project")?;

temp_dir.path()
};

let build_path = root.join("build");
let artifacts_path = root.join("artifacts");

let mut build = build_executable_with_rust_project(
env,
Expand Down