Skip to content

Commit

Permalink
build: fix cargo publish by symlinking cli/docs->docs
Browse files Browse the repository at this point in the history
I think `cargo publish` will currently fail because of the
`include_str!()` in `cli/src/commands/help.rs` pointing to
`../../../docs/`, i.e. outside of the crate directory. This patch
attempts to fix that creating a `cli/docs` symlink to `docs` and makes
the `include_str!` use that symlink. I hope the symlink will be
resolved at `cargo publish` time so it also works in the published
crate.

Because symlinks don't work well on Windows, I updated `cli/build.rs`
to include the original path (the one pointing outside the crate) if
`cli/docs` is not a symlink, so the regular build still should work on
Windows (but `cargo publish` won't).

Thanks to Yuya for proposing this solution.
  • Loading branch information
martinvonz committed Nov 6, 2024
1 parent 1042448 commit e4bf147
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ include = [
"/build.rs",
"/examples/",
"/src/",
"/docs/**",
"/testing/",
"/tests/",
"!*.pending-snap",
Expand Down
8 changes: 8 additions & 0 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ fn main() {
} else {
println!("cargo:rustc-env=JJ_VERSION={version}");
}

let docs_symlink_path = Path::new("docs");
println!("cargo:rerun-if-changed={}", docs_symlink_path.display());
if docs_symlink_path.join("index.md").exists() {
println!("cargo:rustc-env=JJ_DOCS_DIR=docs/");
} else {
println!("cargo:rustc-env=JJ_DOCS_DIR=../docs/");
}
}

fn get_git_hash() -> Option<String> {
Expand Down
1 change: 1 addition & 0 deletions cli/docs
4 changes: 2 additions & 2 deletions cli/src/commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ const KEYWORDS: &[Keyword] = &[
Keyword {
name: "revsets",
description: "A functional language for selecting a set of revision",
content: include_str!("../../../docs/revsets.md"),
content: include_str!(concat!("../../", env!("JJ_DOCS_DIR"), "revsets.md")),
},
Keyword {
name: "tutorial",
description: "Show a tutorial to get started with jj",
content: include_str!("../../../docs/tutorial.md"),
content: include_str!(concat!("../../", env!("JJ_DOCS_DIR"), "tutorial.md")),
},
];

Expand Down
Empty file added foo bar
Empty file.

0 comments on commit e4bf147

Please sign in to comment.