just: fix cross-compilation (#351032)

This commit is contained in:
misuzu 2025-01-15 19:51:39 +02:00 committed by GitHub
commit d6786fd31d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,16 +9,25 @@
libiconv, libiconv,
mdbook, mdbook,
nix-update-script, 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 { rustPlatform.buildRustPackage rec {
pname = "just"; pname = "just";
version = "1.38.0"; version = "1.38.0";
outputs = [ outputs =
"out" [
"man" "out"
"doc" ]
]; ++ lib.optionals installManPages [
"man"
]
++ lib.optionals withDocumentation [ "doc" ];
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "casey"; owner = "casey";
@ -29,10 +38,9 @@ rustPlatform.buildRustPackage rec {
cargoHash = "sha256-JHLkjMy5b1spJrAqFCCzqgnlYTAKA1Z9Tx4w1WWuiAI="; cargoHash = "sha256-JHLkjMy5b1spJrAqFCCzqgnlYTAKA1Z9Tx4w1WWuiAI=";
nativeBuildInputs = [ nativeBuildInputs =
installShellFiles lib.optionals (installShellCompletions || installManPages) [ installShellFiles ]
mdbook ++ lib.optionals withDocumentation [ mdbook ];
];
buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ]; buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ];
preCheck = '' preCheck = ''
@ -61,22 +69,9 @@ rustPlatform.buildRustPackage rec {
./fix-just-path-in-tests.patch ./fix-just-path-in-tests.patch
]; ];
postBuild = '' cargoBuildFlags = [
cargo run --package generate-book "--package=just"
] ++ (lib.optionals withDocumentation [ "--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 .
'';
checkFlags = [ checkFlags = [
"--skip=backticks::trailing_newlines_are_stripped" # Wants to use python3 as alternate shell "--skip=backticks::trailing_newlines_are_stripped" # Wants to use python3 as alternate shell
@ -87,16 +82,26 @@ rustPlatform.buildRustPackage rec {
"--skip=shebang::run_shebang" # test case very rarely fails with "Text file busy" "--skip=shebang::run_shebang" # test case very rarely fails with "Text file busy"
]; ];
postInstall = '' postInstall =
mkdir -p $doc/share/doc/$name lib.optionalString withDocumentation ''
mv ./book/en/build/html $doc/share/doc/$name $out/bin/generate-book
installManPage man/just.1 rm $out/bin/generate-book
# No linkcheck in sandbox
installShellCompletion --cmd just \ echo 'optional = true' >> book/en/book.toml
--bash completions/just.bash \ mdbook build book/en
--fish completions/just.fish \ mkdir -p $doc/share/doc/$name
--zsh completions/just.zsh mv ./book/en/build/html $doc/share/doc/$name
''; ''
+ lib.optionalString installManPages ''
$out/bin/just --man > ./just.1
installManPage ./just.1
''
+ lib.optionalString installShellCompletions ''
installShellCompletion --cmd just \
--bash <($out/bin/just --completions bash) \
--fish <($out/bin/just --completions fish) \
--zsh <($out/bin/just --completions zsh)
'';
setupHook = ./setup-hook.sh; setupHook = ./setup-hook.sh;