Unverified Commit d6786fd3 authored by misuzu's avatar misuzu Committed by GitHub
Browse files

just: fix cross-compilation (#351032)

parents 7bbbbd4a e9126cb7
Loading
Loading
Loading
Loading
+40 −35
Original line number Diff line number Diff line
@@ -9,16 +9,25 @@
  libiconv,
  mdbook,
  nix-update-script,
  # run the compiled `just` to build the completions
  installShellCompletions ? stdenv.buildPlatform.canExecute stdenv.hostPlatform,
  # run the compiled `just` to build the man pages
  installManPages ? stdenv.buildPlatform.canExecute stdenv.hostPlatform,
  # run the compiled `generate-book` utility to prepare the files for mdbook
  withDocumentation ? stdenv.buildPlatform.canExecute stdenv.hostPlatform,
}:

rustPlatform.buildRustPackage rec {
  pname = "just";
  version = "1.38.0";
  outputs = [
  outputs =
    [
      "out"
    ]
    ++ lib.optionals installManPages [
      "man"
    "doc"
  ];
    ]
    ++ lib.optionals withDocumentation [ "doc" ];

  src = fetchFromGitHub {
    owner = "casey";
@@ -29,10 +38,9 @@ rustPlatform.buildRustPackage rec {

  cargoHash = "sha256-JHLkjMy5b1spJrAqFCCzqgnlYTAKA1Z9Tx4w1WWuiAI=";

  nativeBuildInputs = [
    installShellFiles
    mdbook
  ];
  nativeBuildInputs =
    lib.optionals (installShellCompletions || installManPages) [ installShellFiles ]
    ++ lib.optionals withDocumentation [ mdbook ];
  buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ];

  preCheck = ''
@@ -61,22 +69,9 @@ rustPlatform.buildRustPackage rec {
    ./fix-just-path-in-tests.patch
  ];

  postBuild = ''
    cargo run --package generate-book

    mkdir -p completions man

    cargo run -- --man > man/just.1

    for shell in bash fish zsh; do
        cargo run -- --completions $shell > completions/just.$shell
    done

    # No linkcheck in sandbox
    echo 'optional = true' >> book/en/book.toml
    mdbook build book/en
    find .
  '';
  cargoBuildFlags = [
    "--package=just"
  ] ++ (lib.optionals withDocumentation [ "--package=generate-book" ]);

  checkFlags = [
    "--skip=backticks::trailing_newlines_are_stripped" # Wants to use python3 as alternate shell
@@ -87,15 +82,25 @@ rustPlatform.buildRustPackage rec {
    "--skip=shebang::run_shebang" # test case very rarely fails with "Text file busy"
  ];

  postInstall = ''
  postInstall =
    lib.optionalString withDocumentation ''
      $out/bin/generate-book
      rm $out/bin/generate-book
      # No linkcheck in sandbox
      echo 'optional = true' >> book/en/book.toml
      mdbook build book/en
      mkdir -p $doc/share/doc/$name
      mv ./book/en/build/html $doc/share/doc/$name
    installManPage man/just.1

    ''
    + lib.optionalString installManPages ''
      $out/bin/just --man > ./just.1
      installManPage ./just.1
    ''
    + lib.optionalString installShellCompletions ''
      installShellCompletion --cmd just \
      --bash completions/just.bash \
      --fish completions/just.fish \
      --zsh completions/just.zsh
        --bash <($out/bin/just --completions bash) \
        --fish <($out/bin/just --completions fish) \
        --zsh <($out/bin/just --completions zsh)
    '';

  setupHook = ./setup-hook.sh;