I’ve been trying to build a dotnet program that includes AspectInjector. This is the general jist of it:
flake.nix
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.${system}.default =
pkgs.mkShell
{
nativeBuildInputs = [
pkgs.dotnetCorePackages.sdk_7_0
];
};
};
}
$ mkdir aspect-injector-project
$ cd aspect-injector-project
$ <put flake.nix into dir>
$ nix develop
$ dotnet new console
$ dotnet build
<it succeeds>
$ dotnet add package AspectInjector
<installs version 2.8.2>
$ dotnet build -v d
<it fails>
In the build detailed output this seems to where it fails:
1:7>Target "_ASI_InjectAspectsCore" in file "/home/mark/.nuget/packages/aspectinjector/2.8.2/buildTransitive/netstandard2.0/AspectInjector.targets" from project "/home/mark/projects/aspect-injector-project/aspect-injector-project.csproj" (target "InjectAspects" depends on it):
Task "Message" skipped, due to false condition; ( '$(AspectInjector_Debug)' == 'true' ) was evaluated as ( 'false' == 'true' ).
Using "Exec" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Task "Exec"
/tmp/nix-shell.KSYnpM/MSBuildTempmark/tmp982d30c4c57444179a1963846db707a0.exec.cmd: line 2: /home/mark/.nuget/packages/aspectinjector/2.8.2/buildTransitive/netstandard2.0/../../build/_bin/linux-x64/AspectInjector: cannot execute: required file not found
Done executing task "Exec".
Which I believe suggests the error happens on L47 of this file: https://github.com/pamidur/aspect-injector/blob/cbafc5afc23ca6f49863042cafb3c9ba91b0ca0a/nuget/build/AspectInjector.targets
<_ProcessCmd>"$(AspectInjector_Location)"$(_CmdParams) -rf "%(IntermediateAssembly.FullPath)$(_ASI_RefsFileExt)" "@(IntermediateAssembly->'%(FullPath)')"</_ProcessCmd>
It seems that IntermediateAssembly.FullPath
is linking to /nix/store/
and looking for files created in a previous build step that are not there.
It is this point that my lack of msbuild and nix knowledge hits home and I’m unsure how to proceed. I’m hoping there is a fairly simple fix/workaround for this. How’s my luck?
I have made some progress. I believe I was right about the msbuild line that was failing. On that line it tries to execute
"/home/mark/.nuget/packages/aspectinjector/2.8.2/buildTransitive/netstandard2.0/../../build/_bin/linux-x64/AspectInjector" -d -rf "/home/mark/projects/simple-aspectinject/obj/Debug/net7.0/simple-aspectinject.dll._asi_refs" "/home/mark/projects/simple-aspectinject/obj/Debug/net7.0/simple-aspectinject.dll"
And so eventually I tried this that reveals the problem:
[nix-shell:~/.nuget/packages/aspectinjector/2.8.2/build/_bin/linux-x64]$ ldd AspectInjector
linux-vdso.so.1 (0x00007ffe541a8000)
libpthread.so.0 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libpthread.so.0 (0x00007f990d9fb000)
libdl.so.2 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libdl.so.2 (0x00007f990d9f6000)
libz.so.1 => not found
librt.so.1 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/librt.so.1 (0x00007f990d9f1000)
libgcc_s.so.1 => /nix/store/jd99cyc0251p0i5y69w8mqjcai8mcq7h-xgcc-12.2.0-libgcc/lib/libgcc_s.so.1 (0x00007f990d9d0000)
libstdc++.so.6 => not found
libm.so.6 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libm.so.6 (0x00007f990d8ee000)
libc.so.6 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6 (0x00007f990d708000)
/lib64/ld-linux-x86-64.so.2 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib64/ld-linux-x86-64.so.2 (0x00007f990e47f000)
So it looks like the AspectInjector
binary that is executing during dotnet build
cannot find zlib or the c++ std lib dynamic libraries.
Edit: Managed to fix that issue by using this
flake.nix
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
deps = [
pkgs.zlib
pkgs.zlib.dev
pkgs.libstdcxx5
pkgs.dotnetCorePackages.sdk_7_0
];
in
{
devShells.${system}.default =
pkgs.mkShell
{
nativeBuildInputs = [
pkgs.dotnetCorePackages.sdk_7_0
pkgs.nix-ld
] ++ deps;
NIX_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath ([
pkgs.stdenv.cc.cc
] ++ deps);
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath ([
pkgs.stdenv.cc.cc
] ++ deps);
NIX_LD = "${pkgs.stdenv.cc.libc_bin}/bin/ld.so";
};
};
}
But the build still fails:
$ nix develop
$ dotnet build
<fails with error including...>
/tmp/nix-shell.VhZ4h2/MSBuildTempmark/tmpe144ebc8999d4a95af5ed396537fb31f.exec.cmd: line 2: /home/mark/.nuget/packages/aspectinjector/2.8.2/buildTransitive/netstandard2.0/../../build/_bin/linux-x64/AspectInjector: cannot execute: required file not found
$ ldd /home/mark/.nuget/packages/aspectinjector/2.8.2/buildTransitive/netstandard2.0/../../build/_bin/linux-x64/AspectInjector
linux-vdso.so.1 (0x00007ffff7fc8000)
libpthread.so.0 => /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/libpthread.so.0 (0x00007ffff7fbd000)
libdl.so.2 => /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/libdl.so.2 (0x00007ffff7fb8000)
libz.so.1 => /nix/store/ig0kkzw4n2pws12dj7szjm71f1a43if6-zlib-1.3/lib/libz.so.1 (0x00007ffff7f9a000)
librt.so.1 => /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/librt.so.1 (0x00007ffff7f95000)
libgcc_s.so.1 => /nix/store/xq05361kqwzcdamcsxr4gzg8ksxrb8sg-gcc-12.3.0-lib/lib/libgcc_s.so.1 (0x00007ffff7f72000)
libstdc++.so.6 => /nix/store/xq05361kqwzcdamcsxr4gzg8ksxrb8sg-gcc-12.3.0-lib/lib/libstdc++.so.6 (0x00007ffff7000000)
libm.so.6 => /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/libm.so.6 (0x00007ffff7e92000)
libc.so.6 => /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/libc.so.6 (0x00007ffff6e1a000)
/lib64/ld-linux-x86-64.so.2 => /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib64/ld-linux-x86-64.so.2 (0x00007ffff7fca000)
I found this post that seems to be someone suffering from the same issue: bash - Cannot exceute binary: required file not found - Unix & Linux Stack Exchange