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

Fix incremental compilation by using separate target dir for front #203

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ lib-profile-release = "my-release-profile"
#
# Optional. Defaults to "debug".
lib-profile-dev = "my-debug-profile"

# Fixes cargo bug that prevents incremental compilation (see #203)
#
# Optional. Defaults to false
separate-front-target-dir = true
```

## Site parameters
Expand Down
5 changes: 5 additions & 0 deletions src/compile/front.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ pub fn build_cargo_front_cmd(
format!("--package={}", proj.lib.name.as_str()),
"--lib".to_string(),
];

if let Some(path) = &proj.lib.front_target_path {
args.push(format!("--target-dir={path}"))
}

if wasm {
args.push("--target=wasm32-unknown-unknown".to_string());
}
Expand Down
17 changes: 14 additions & 3 deletions src/config/lib_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct LibPackage {
pub default_features: bool,
pub output_name: String,
pub src_paths: Vec<Utf8PathBuf>,
pub front_target_path: Option<Utf8PathBuf>,
pub profile: Profile,
}

Expand Down Expand Up @@ -65,9 +66,11 @@ impl LibPackage {
);

let wasm_file = {
let source = metadata
// Can't use absolute path because the path gets stored in snapshot testing, and it differs between developers
.rel_target_dir()
let mut source = metadata.rel_target_dir();
if config.separate_front_target_dir {
source = source.join("front");
}
let source = source
.join("wasm32-unknown-unknown")
.join(profile.to_string())
.join(name.replace('-', "_"))
Expand All @@ -92,6 +95,13 @@ impl LibPackage {
} else {
src_deps.push(rel_dir.join("src"));
}

let front_target_path = if config.separate_front_target_dir {
Some(metadata.target_directory.join("front"))
} else {
None
};

Ok(Self {
name,
abs_dir,
Expand All @@ -102,6 +112,7 @@ impl LibPackage {
default_features: config.lib_default_features,
output_name,
src_paths: src_deps,
front_target_path,
profile,
})
}
Expand Down
3 changes: 3 additions & 0 deletions src/config/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ pub struct ProjectConfig {
#[serde(skip)]
pub config_dir: Utf8PathBuf,

#[serde(default)]
pub separate_front_target_dir: bool,

// Profiles
pub lib_profile_dev: Option<String>,
pub lib_profile_release: Option<String>,
Expand Down
Loading