Hi,

On Thu, Jan 18, 2024 at 09:44:20AM -0000, Laurent Cheylus wrote:
> - Add MAKE_ENV += CFG_RELEASE=${GH_TAGNAME} to set version
> - Add post-build to generate HTML doc with asciidoctor
> - Install binary and doc in do-install

Thanks!

I've looked at Laurent's openbsd-wip port and incorporated the bits we missed,
albeit with tweaks:

 - convert `do-install` to a `post-install` without the explicit binary install
   step.

 - remove this from `post-build`:
    ```
        ${MODCARGO_CARGO_RUN} test \
                --manifest-path ${MODCARGO_CARGOTOML} \
                --offline \
                --release \
                --verbose \
                -p ide-assists \
                -p ide-diagnostics \
                -p rust-analyzer \
                -- sourcegen_
    ```

    As far as I can see, that runs a test, which we already have an implicit
    target for.

While here, also fix the tests:
 - Don't invoke `rustfmt` via `rustup`.
 - Workaround `rustfmt` version quirk.

About the latter, the tests expect "stable" to appear in the output of `rustfmt
--version`. But that's not so for our package:

```
$ rustfmt --version   
rustfmt 1.7.0-
```

I suspect it should return `rustfmt 1.7.0-stable`? CC semarie@

Anyway, below is a diff showing what I changed, and I've attached a tarball for
convenience.

Still OK?


diff -urNa rust-analyzer.old/Makefile rust-analyzer/Makefile
--- rust-analyzer.old/Makefile  Fri Jan 19 10:49:54 2024
+++ rust-analyzer/Makefile      Fri Jan 19 11:16:07 2024
@@ -12,7 +12,11 @@
 # MIT OR Apache-2.0
 PERMIT_PACKAGE =       Yes
 
-RUN_DEPENDS =  lang/rust,-src
+RUN_DEPENDS =  lang/rust,-src \
+               lang/rust,-rustfmt
+BUILD_DEPENDS =        ${RUN_DEPENDS} \
+               textproc/ruby-rouge \
+               textproc/asciidoctor
 
 WANTLIB += ${MODCARGO_WANTLIB} m
 
@@ -23,6 +27,19 @@
 SEPARATE_BUILD =       Yes
 
 CONFIGURE_STYLE =      cargo
+
+# Make `rust-analyzer --version` print the right thing.
+# (otherwise it reports itself as version 0.0.0)
+MAKE_ENV += CFG_RELEASE=${GH_TAGNAME}
+
+# generate manual.html
+post-build:
+       asciidoctor ${WRKSRC}/docs/user/manual.adoc
+
+DOCDIR =       ${PREFIX}/share/doc/rust-analyzer
+post-install:
+       ${INSTALL_DATA_DIR} ${DOCDIR}
+       ${INSTALL_DATA} ${WRKSRC}/docs/user/manual.html ${DOCDIR}
 
 .include "crates.inc"
 
diff -urNa 
rust-analyzer.old/patches/patch-crates_rust-analyzer_tests_slow-tests_tidy_rs 
rust-analyzer/patches/patch-crates_rust-analyzer_tests_slow-tests_tidy_rs
--- 
rust-analyzer.old/patches/patch-crates_rust-analyzer_tests_slow-tests_tidy_rs   
    Thu Jan  1 01:00:00 1970
+++ rust-analyzer/patches/patch-crates_rust-analyzer_tests_slow-tests_tidy_rs   
Fri Jan 19 13:48:06 2024
@@ -0,0 +1,31 @@
+Don't use rustup. Work around OpenBSD rustfmt bug.
+
+Index: crates/rust-analyzer/tests/slow-tests/tidy.rs
+--- crates/rust-analyzer/tests/slow-tests/tidy.rs.orig
++++ crates/rust-analyzer/tests/slow-tests/tidy.rs
+@@ -14,17 +14,17 @@ fn check_code_formatting() {
+     let sh = &Shell::new().unwrap();
+     sh.change_dir(sourcegen::project_root());
+ 
+-    let out = cmd!(sh, "rustup run stable rustfmt --version").read().unwrap();
+-    if !out.contains("stable") {
+-        panic!(
+-            "Failed to run rustfmt from toolchain 'stable'. \
+-                 Please run `rustup component add rustfmt --toolchain stable` 
to install it.",
+-        )
++    let out = cmd!(sh, "rustfmt --version").read().unwrap();
++    // FIXME: OpenBSD's rustfmt doesn't report it's version correctly.
++    // At the time of writing, `rustfmt --version` gives `rustfmt 1.7.0-` 
(i.e. missing the
++    // `-stable` suffix.
++    if !out.contains("rustfmt") {
++        panic!("Failed to run rustfmt from toolchain 'stable'.");
+     }
+ 
+-    let res = cmd!(sh, "rustup run stable cargo fmt -- --check").run();
++    let res = cmd!(sh, "cargo fmt -- --check").run();
+     if res.is_err() {
+-        let _ = cmd!(sh, "rustup run stable cargo fmt").run();
++        let _ = cmd!(sh, "cargo fmt").run();
+     }
+     res.unwrap()
+ }
diff -urNa rust-analyzer.old/patches/patch-crates_sourcegen_src_lib_rs 
rust-analyzer/patches/patch-crates_sourcegen_src_lib_rs
--- rust-analyzer.old/patches/patch-crates_sourcegen_src_lib_rs Thu Jan  1 
01:00:00 1970
+++ rust-analyzer/patches/patch-crates_sourcegen_src_lib_rs     Fri Jan 19 
13:49:54 2024
@@ -0,0 +1,42 @@
+Don't use rustup. Work around OpenBSD rustfmt bug.
+
+Index: crates/sourcegen/src/lib.rs
+--- crates/sourcegen/src/lib.rs.orig
++++ crates/sourcegen/src/lib.rs
+@@ -133,12 +133,12 @@ impl fmt::Display for Location {
+ }
+ 
+ fn ensure_rustfmt(sh: &Shell) {
+-    let version = cmd!(sh, "rustup run stable rustfmt 
--version").read().unwrap_or_default();
+-    if !version.contains("stable") {
+-        panic!(
+-            "Failed to run rustfmt from toolchain 'stable'. \
+-                 Please run `rustup component add rustfmt --toolchain stable` 
to install it.",
+-        );
++    let version = cmd!(sh, "rustfmt --version").read().unwrap_or_default();
++    // FIXME: OpenBSD's rustfmt doesn't report it's version correctly.
++    // At the time of writing, `rustfmt --version` gives `rustfmt 1.7.0-` 
(i.e. missing the
++    // `-stable` suffix.
++    if !version.contains("rustfmt") {
++        panic!("Failed to run rustfmt from toolchain 'stable'.");
+     }
+ }
+ 
+@@ -146,13 +146,10 @@ pub fn reformat(text: String) -> String {
+     let sh = Shell::new().unwrap();
+     ensure_rustfmt(&sh);
+     let rustfmt_toml = project_root().join("rustfmt.toml");
+-    let mut stdout = cmd!(
+-        sh,
+-        "rustup run stable rustfmt --config-path {rustfmt_toml} --config 
fn_single_line=true"
+-    )
+-    .stdin(text)
+-    .read()
+-    .unwrap();
++    let mut stdout = cmd!(sh, "rustfmt --config-path {rustfmt_toml} --config 
fn_single_line=true")
++        .stdin(text)
++        .read()
++        .unwrap();
+     if !stdout.ends_with('\n') {
+         stdout.push('\n');
+     }
diff -urNa rust-analyzer.old/pkg/PLIST rust-analyzer/pkg/PLIST
--- rust-analyzer.old/pkg/PLIST Fri Jan 19 10:49:54 2024
+++ rust-analyzer/pkg/PLIST     Fri Jan 19 11:13:23 2024
@@ -1 +1,3 @@
 @bin bin/rust-analyzer
+share/doc/rust-analyzer/
+share/doc/rust-analyzer/manual.html

-- 
Best Regards
Edd Barrett

https://www.theunixzoo.co.uk

Attachment: ra.tgz
Description: application/tar-gz

Reply via email to