Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions pkgs/by-name/wa/wasmtime/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
stdenv,
rustPlatform,
fetchFromGitHub,
buildPackages,
cmake,
installShellFiles,
versionCheckHook,
nix-update-script,
enableShared ? !stdenv.hostPlatform.isStatic,
enableStatic ? stdenv.hostPlatform.isStatic,
}:
rustPlatform.buildRustPackage (finalAttrs: {
pname = "wasmtime";
Expand Down Expand Up @@ -35,7 +39,10 @@ rustPlatform.buildRustPackage (finalAttrs: {
"dev"
];

nativeBuildInputs = [ cmake ];
nativeBuildInputs = [
cmake
installShellFiles
];

doCheck =
with stdenv.buildPlatform;
Expand All @@ -54,10 +61,12 @@ rustPlatform.buildRustPackage (finalAttrs: {

postInstall =
let
inherit (stdenv.targetPlatform.rust) cargoShortTarget;
inherit (stdenv.hostPlatform.rust) cargoShortTarget;
in
''
moveToOutput lib $dev
${lib.optionalString (!enableShared) "rm $dev/lib/*.so{,.*}"}
${lib.optionalString (!enableStatic) "rm $dev/lib/*.a"}

# copy the build.rs generated c-api headers
# https://github.com/rust-lang/cargo/issues/9661
Expand All @@ -67,6 +76,18 @@ rustPlatform.buildRustPackage (finalAttrs: {
install_name_tool -id \
$dev/lib/libwasmtime.dylib \
$dev/lib/libwasmtime.dylib
''
+ lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
installShellCompletion --cmd wasmtime \
--bash <("$out/bin/wasmtime" completion bash) \
--zsh <("$out/bin/wasmtime" completion zsh) \
--fish <("$out/bin/wasmtime" completion fish)
''
+ lib.optionalString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
installShellCompletion --cmd wasmtime \
--bash "${buildPackages.wasmtime}"/share/bash-completion/completions/*.bash \
--zsh "${buildPackages.wasmtime}"/share/zsh/site-functions/* \
--fish "${buildPackages.wasmtime}"/share/fish/*/*
'';
Comment on lines +80 to 91
Copy link
Member

Choose a reason for hiding this comment

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

Do you know if there's a difference between those two in practice? (Does wasmtime completion do anything other than cat the completion files?).

I'm asking because if not, we could simplify to just run the second option in both cases, when stdenv.buildPlatform.canExecute and when it cannot.

Copy link
Member Author

Choose a reason for hiding this comment

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

So my understanding of this snippet (referenced from tree-sitter's nixpkgs shell completions) is that this is for pkgsCross cross compilation. First we need wasmtime completion to put the files under $out/share/{bash,fish,zsh} on our native architecture.
Then when building e.g. pkgsCross.armv7l-hf-multiplatform.wasmtime, buildPackages refers to the host architecture; the completions are copied from there to the cross-compilation target, since the build platform can't run wasmtime completion itself if it's targeting armv7.

I actually just tried this on my end with nix-build . -A pkgsCross.armv7l-hf-multiplatform.wasmtime and have noticed that our cargoShortTarget is wrong. I think it should be stdenv.hostPlatform instead of stdenv.targetPlatform, because the C API header cp fails.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see, thank you. I didn't know this construct; out of interest I tried to use the second option and I run into infinite recursion, so I see now. The solution on this PR is working as expected:

❯ tree result
result
├── bin
│   └── wasmtime
└── share
    ├── bash-completion
    │   └── completions
    │       └── wasmtime.bash
    ├── fish
    │   └── vendor_completions.d
    │       └── wasmtime.fish
    └── zsh
        └── site-functions
            └── _wasmtime


nativeInstallCheckInputs = [
Expand Down
Loading