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

Martin-ui packaging issue #1699

Merged
merged 20 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ccf7802
Martin-ui packaging issue
nyurik Feb 23, 2025
47aca2e
test if setting the toolchain to nightly means that +nightly need not…
CommanderStorm Feb 23, 2025
5032691
fix building the frontend 'wrong'
CommanderStorm Feb 23, 2025
c9168e3
fix building paths wrong on non-unix platforms
CommanderStorm Feb 23, 2025
246513a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 23, 2025
58a70b4
remove accidentally change detecting twice
CommanderStorm Feb 23, 2025
3769c02
added a bunch of assertions and debug comments to track down where th…
CommanderStorm Feb 23, 2025
32e0697
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 23, 2025
a5d4a3a
Merge branch 'main' into npm-fix
CommanderStorm Feb 23, 2025
d4437f7
migrate to using symlinks instead of copying
CommanderStorm Mar 2, 2025
385ffbd
fix the martin logo having gotten corrupted in a previous commit
CommanderStorm Mar 2, 2025
f2c7b62
Revert "migrate to using symlinks instead of copying"
CommanderStorm Mar 2, 2025
aee24c8
Merge branch 'main' into npm-fix
CommanderStorm Mar 2, 2025
20b8998
simplified the code and hopefully fixed the last CI-local enviromentn…
CommanderStorm Mar 2, 2025
1ca25a3
Merge branch 'main' into npm-fix
nyurik Mar 4, 2025
3b986eb
Refactored build script, use `walkdir`
nyurik Mar 4, 2025
98aca25
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 4, 2025
f5cfec2
walkdir usage
nyurik Mar 4, 2025
a75f07d
Update martin/build.rs
nyurik Mar 4, 2025
331d566
review fixes
nyurik Mar 4, 2025
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
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
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
78 changes: 75 additions & 3 deletions martin/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,85 @@
#[cfg(feature = "webui")]
/// copies a directory and its contents to a new location recursively
fn copy_dir_all(
src: &std::path::PathBuf,
dst: &std::path::PathBuf,
exclude_dirs: &[std::path::PathBuf],
) -> std::io::Result<()> {
assert!(!exclude_dirs.contains(src));
assert!(
src.is_dir(),
"source for the copy operation is not an existing directory"
);
assert!(
!dst.exists(),
"destination for the copy operation must not exist"
);
std::fs::create_dir_all(dst)?;

for entry in std::fs::read_dir(src)? {
let entry = entry?;
let ty = entry.file_type()?;
let src_path = entry.path();
let dst_path = dst.join(entry.file_name());
if ty.is_dir() {
if exclude_dirs.contains(&src_path) {
continue;
}
copy_dir_all(&src_path, &dst_path, exclude_dirs)?;
} else {
std::fs::copy(src_path, dst_path)?;
}
}
Ok(())
}

fn main() -> std::io::Result<()> {
#[cfg(feature = "webui")]
{
static_files::NpmBuild::new("martin-ui")
// 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 and
// - build the frontend
let martin_ui_dir = std::env::current_dir()?.join("martin-ui");
assert!(martin_ui_dir.is_dir(), "martin-ui directory does not exist");
let out_dir = std::env::var("OUT_DIR")
.unwrap()
.parse::<std::path::PathBuf>()
.unwrap();
let out_martin_ui_dir = out_dir.join("martin-ui");
if out_martin_ui_dir.exists() {
std::fs::remove_dir_all(&out_martin_ui_dir)?;
}
copy_dir_all(
&martin_ui_dir,
&out_martin_ui_dir,
&[
martin_ui_dir.join("dist"),
martin_ui_dir.join("node_modules"),
],
)?;

println!("installing and building in {out_martin_ui_dir:?}");
static_files::NpmBuild::new(&out_martin_ui_dir)
.install()?
.run("build")?
.target("martin-ui/dist")
.change_detection()
.target(out_martin_ui_dir.join("dist"))
.to_resource_dir()
.build()?;
// Above code does have the problem that change detection would not be working properly.
//
// `copy_dir_all` was never anticipated by the crate we use
// => we need to do this with different arguments.
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"
);
static_files::NpmBuild::new(martin_ui_dir)
.target(&target_to_keep)
.change_detection();
}
Ok(())
}
1 change: 1 addition & 0 deletions martin/src/srv/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::MartinResult;
#[cfg(feature = "webui")]
mod webui {
#![allow(clippy::unreadable_literal)]
#![allow(clippy::too_many_lines)]
#![allow(clippy::wildcard_imports)]
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
}
Expand Down
Loading