Skip to content

Commit

Permalink
Fix incremental compilation by using separate target dir for front (#203
Browse files Browse the repository at this point in the history
)

* fix incremental compilation by using separate target dir for front
* add documentation to README
  • Loading branch information
crapStone committed Oct 13, 2023
1 parent 1fe83eb commit 3bdaa8d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
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

0 comments on commit 3bdaa8d

Please sign in to comment.