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

build: fix cargo publish by symlinking cli/docs->docs #4773

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

martinvonz
Copy link
Member

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@thoughtpolice
Copy link
Collaborator

FWIW, my other comment on #4630 was meant to say we should:

  1. Write a build.rs that copies the docs directory to $OUT_DIR, which is a variable provided to the build script: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
  2. Then, change the include_str!() call to instead do something like:
const DOCS_DIR = concat!(env!("OUT_DIR"), "/docs")

since $OUT_DIR will also be set during the build process, too.

However, I'm still not sure this will solve the problem, because I don't know if the .crate itself will get those files. So maybe we do have to symlink things which... Ugh. Well, maybe it's all we can do...

@thoughtpolice
Copy link
Collaborator

I also wonder if there's a way to test cargo publish before we actually merge a PR...

@martinvonz
Copy link
Member Author

However, I'm still not sure this will solve the problem, because I don't know if the .crate itself will get those files. So maybe we do have to symlink things which... Ugh. Well, maybe it's all we can do...

Yes, I suspect so.

I also wonder if there's a way to test cargo publish before we actually merge a PR...

I tested it with cargo publish --dry-run, which fails with lots of compilation errors because the jj-cli points to the published 0.22.0 version of jj-lib, but it also seems to show that the include_str! does not work. The include_str! error goes away with this PR.

Copy link
Collaborator

@yuja yuja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

cli/build.rs Outdated Show resolved Hide resolved
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.
@martinvonz martinvonz enabled auto-merge (rebase) November 6, 2024 01:26
@martinvonz martinvonz merged commit e4bf147 into main Nov 6, 2024
31 checks passed
@martinvonz martinvonz deleted the push-wzlxtlqxmoyk branch November 6, 2024 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants