-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run `npm install` and javascript packaging inside the `OUT_DIR` ``` error: failed to verify package tarball Caused by: Source directory was modified by build.rs during cargo publish. Build scripts should not modify anything outside of OUT_DIR. Added: .../martin/target/package/martin-0.15.0/martin-ui/dist .../martin/target/package/martin-0.15.0/martin-ui/dist/_ .../martin/target/package/martin-0.15.0/martin-ui/dist/_/assets ... ``` Fixes #1667 See prior partial fix in #1668 --------- Co-authored-by: Frank Elsinga <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Frank Elsinga <[email protected]>
- Loading branch information
1 parent
7555baa
commit 48ff2c1
Showing
11 changed files
with
163 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Packaging and release | ||
|
||
# For now this is only testing that packaging will be possible in the future | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
paths-ignore: | ||
- '**.md' | ||
- 'demo/**' | ||
- 'docs/**' | ||
pull_request: | ||
branches: [ main ] | ||
paths-ignore: | ||
- '**.md' | ||
- 'demo/**' | ||
- 'docs/**' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v4 | ||
- uses: Swatinem/rust-cache@v2 | ||
- name: Install nightly toolchain | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: nightly | ||
- name: Test packaging | ||
run: cargo publish --workspace -Z package-workspace --dry-run |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,107 @@ | ||
fn main() -> std::io::Result<()> { | ||
#[cfg(feature = "webui")] | ||
{ | ||
static_files::NpmBuild::new("martin-ui") | ||
.install()? | ||
.run("build")? | ||
.target("martin-ui/dist") | ||
.change_detection() | ||
.to_resource_dir() | ||
.build()?; | ||
#[cfg(feature = "webui")] | ||
use std::fs; | ||
#[cfg(feature = "webui")] | ||
use std::path::Path; | ||
|
||
#[cfg(feature = "webui")] | ||
fn copy_file_tree(src: &Path, dst: &Path, exclude_dirs: &[&str]) { | ||
assert!( | ||
src.is_dir(), | ||
"source for the copy operation is not an existing directory" | ||
); | ||
let _ = fs::remove_dir_all(dst); // ignore if dir does not exist | ||
fs::create_dir_all(dst).unwrap_or_else(|e| { | ||
panic!( | ||
"failed to create destination directory {}: {e}", | ||
dst.display() | ||
) | ||
}); | ||
let excludes = exclude_dirs.iter().map(|v| src.join(v)).collect::<Vec<_>>(); | ||
|
||
let mut it = walkdir::WalkDir::new(src).follow_links(true).into_iter(); | ||
while let Some(entry) = it.next() { | ||
let entry = entry.expect("failed to read directory entry"); | ||
if excludes.iter().any(|v| v == entry.path()) { | ||
it.skip_current_dir(); | ||
continue; | ||
} | ||
|
||
// Get the relative path of the entry | ||
let dst_path = dst.join( | ||
entry | ||
.path() | ||
.strip_prefix(src) | ||
.expect("path is not a prefix of the source directory"), | ||
); | ||
|
||
if entry.file_type().is_dir() { | ||
fs::create_dir_all(&dst_path).unwrap_or_else(|e| { | ||
panic!( | ||
"failed to create destination directory {}: {e}", | ||
dst_path.display() | ||
) | ||
}); | ||
} else { | ||
fs::copy(entry.path(), &dst_path).unwrap_or_else(|e| { | ||
panic!( | ||
"failed to copy file {} to {}: {e}", | ||
entry.path().display(), | ||
dst_path.display() | ||
) | ||
}); | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[cfg(feature = "webui")] | ||
fn webui() { | ||
// rust requires that all changes are done in OUT_DIR. | ||
// | ||
// We thus need to | ||
// - move the frontend code to the OUT_DIR | ||
// - install npm dependencies | ||
// - build the frontend | ||
let martin_ui_dir = std::env::current_dir() | ||
.expect("Unable to get current dir") | ||
.join("martin-ui"); | ||
assert!(martin_ui_dir.is_dir(), "martin-ui directory does not exist"); | ||
|
||
let out_martin_ui_dir = std::env::var("OUT_DIR") | ||
.expect("OUT_DIR environment variable is not set") | ||
.parse::<std::path::PathBuf>() | ||
.expect("OUT_DIR environment variable is not a valid path") | ||
.join("martin-ui"); | ||
|
||
copy_file_tree( | ||
&martin_ui_dir, | ||
&out_martin_ui_dir, | ||
&["dist", "node_modules"], | ||
); | ||
|
||
println!("installing and building in {out_martin_ui_dir:?}"); | ||
static_files::NpmBuild::new(&out_martin_ui_dir) | ||
.install() | ||
.expect("npm install failed") | ||
.run("build") | ||
.expect("npm run build failed") | ||
.target(out_martin_ui_dir.join("dist")) | ||
.to_resource_dir() | ||
.build() | ||
.expect("failed to build webui npm dir"); | ||
|
||
let target_to_keep = martin_ui_dir.join("dist"); | ||
assert!( | ||
!target_to_keep.exists() || target_to_keep.is_dir(), | ||
"the martin-ui/dist must either not exist or have been produced by previous builds" | ||
); | ||
|
||
// TODO: we may need to move index.html one level down per change_detection() docs | ||
static_files::NpmBuild::new(martin_ui_dir) | ||
.target(&target_to_keep) | ||
.change_detection(); | ||
} | ||
|
||
fn main() { | ||
#[cfg(feature = "webui")] | ||
webui(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters