Skip to content

Commit

Permalink
Merge pull request #313514 from tie/dotnet-cross-split
Browse files Browse the repository at this point in the history
buildDotnetModule: fix cross-compilation and remove dotnet-test-sdk
  • Loading branch information
corngood authored May 23, 2024
2 parents 2ee89d5 + cfd1bd6 commit f17d1f9
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 37 deletions.
1 change: 0 additions & 1 deletion doc/languages-frameworks/dotnet.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ For more detail about managing the `deps.nix` file, see [Generating and updating
* `useDotnetFromEnv` will change the binary wrapper so that it uses the .NET from the environment. The runtime specified by `dotnet-runtime` is given as a fallback in case no .NET is installed in the user's environment. This is most useful for .NET global tools and LSP servers, which often extend the .NET CLI and their runtime should match the users' .NET runtime.
* `dotnet-sdk` is useful in cases where you need to change what dotnet SDK is being used. You can also set this to the result of `dotnetSdkPackages.combinePackages`, if the project uses multiple SDKs to build.
* `dotnet-runtime` is useful in cases where you need to change what dotnet runtime is being used. This can be either a regular dotnet runtime, or an aspnetcore.
* `dotnet-test-sdk` is useful in cases where unit tests expect a different dotnet SDK. By default, this is set to the `dotnet-sdk` attribute.
* `testProjectFile` is useful in cases where the regular project file does not contain the unit tests. It gets restored and build, but not installed. You may need to regenerate your nuget lockfile after setting this. Note that if set, only tests from this project are executed.
* `disabledTests` is used to disable running specific unit tests. This gets passed as: `dotnet test --filter "FullyQualifiedName!={}"`, to ensure compatibility with all unit test frameworks.
* `dotnetRestoreFlags` can be used to pass flags to `dotnet restore`.
Expand Down
4 changes: 1 addition & 3 deletions pkgs/build-support/dotnet/build-dotnet-module/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@
, dotnet-sdk ? dotnetCorePackages.sdk_6_0
# The dotnet runtime to use.
, dotnet-runtime ? dotnetCorePackages.runtime_6_0
# The dotnet SDK to run tests against. This can differentiate from the SDK compiled against.
, dotnet-test-sdk ? dotnet-sdk
, ...
} @ args:

Expand All @@ -96,7 +94,7 @@ let
else dotnet-sdk.meta.platforms;

inherit (callPackage ./hooks {
inherit dotnet-sdk dotnet-test-sdk disabledTests nuget-source dotnet-runtime runtimeDeps buildType;
inherit dotnet-sdk disabledTests nuget-source dotnet-runtime runtimeDeps buildType;
runtimeId =
if runtimeId != null
then runtimeId
Expand Down
55 changes: 28 additions & 27 deletions pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
, makeSetupHook
, makeWrapper
, dotnet-sdk
, dotnet-test-sdk
, disabledTests
, nuget-source
, dotnet-runtime
Expand All @@ -22,10 +21,9 @@ let
libraryPath = lib.makeLibraryPath runtimeDeps;
in
{
dotnetConfigureHook = callPackage ({ }:
makeSetupHook {
dotnetConfigureHook = makeSetupHook
{
name = "dotnet-configure-hook";
propagatedBuildInputs = [ dotnet-sdk nuget-source ];
substitutions = {
nugetSource = nuget-source;
dynamicLinker = "${stdenv.cc}/nix-support/dynamic-linker";
Expand All @@ -38,45 +36,47 @@ in
];
inherit runtimeId;
};
} ./dotnet-configure-hook.sh) { };
}
./dotnet-configure-hook.sh;

dotnetBuildHook = callPackage ({ }:
makeSetupHook {
dotnetBuildHook = makeSetupHook
{
name = "dotnet-build-hook";
propagatedBuildInputs = [ dotnet-sdk ];
substitutions = {
inherit buildType runtimeId;
};
} ./dotnet-build-hook.sh) { };
}
./dotnet-build-hook.sh;

dotnetCheckHook = callPackage ({ }:
makeSetupHook {
dotnetCheckHook = makeSetupHook
{
name = "dotnet-check-hook";
propagatedBuildInputs = [ dotnet-test-sdk ];
substitutions = {
inherit buildType runtimeId libraryPath;
disabledTests = lib.optionalString (disabledTests != [])
(let
escapedNames = lib.lists.map (n: lib.replaceStrings [","] ["%2C"] n) disabledTests;
filters = lib.lists.map (n: "FullyQualifiedName!=${n}") escapedNames;
in
"${lib.concatStringsSep "&" filters}");
disabledTests = lib.optionalString (disabledTests != [ ])
(
let
escapedNames = lib.lists.map (n: lib.replaceStrings [ "," ] [ "%2C" ] n) disabledTests;
filters = lib.lists.map (n: "FullyQualifiedName!=${n}") escapedNames;
in
"${lib.concatStringsSep "&" filters}"
);
};
} ./dotnet-check-hook.sh) { };
}
./dotnet-check-hook.sh;

dotnetInstallHook = callPackage ({ }:
makeSetupHook {
dotnetInstallHook = makeSetupHook
{
name = "dotnet-install-hook";
propagatedBuildInputs = [ dotnet-sdk ];
substitutions = {
inherit buildType runtimeId;
};
} ./dotnet-install-hook.sh) { };
}
./dotnet-install-hook.sh;

dotnetFixupHook = callPackage ({ }:
makeSetupHook {
dotnetFixupHook = makeSetupHook
{
name = "dotnet-fixup-hook";
propagatedBuildInputs = [ dotnet-runtime ];
substitutions = {
dotnetRuntime = dotnet-runtime;
runtimeDeps = libraryPath;
Expand All @@ -85,5 +85,6 @@ in
dirname = "${coreutils}/bin/dirname";
realpath = "${coreutils}/bin/realpath";
};
} ./dotnet-fixup-hook.sh) { };
}
./dotnet-fixup-hook.sh;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dotnetBuildHook() {
runtimeIdFlags+=("--runtime @runtimeId@")
fi

env dotnet build ${project-} \
dotnet build ${project-} \
-maxcpucount:$maxCpuFlag \
-p:BuildInParallel=$parallelBuildFlag \
-p:ContinuousIntegrationBuild=true \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dotnetCheckHook() {
runtimeIdFlags=("--runtime @runtimeId@")
fi

env "LD_LIBRARY_PATH=@libraryPath@" \
LD_LIBRARY_PATH="@libraryPath@" \
dotnet test "$project" \
-maxcpucount:$maxCpuFlag \
-p:ContinuousIntegrationBuild=true \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dotnetConfigureHook() {

dotnetRestore() {
local -r project="${1-}"
env dotnet restore ${project-} \
dotnet restore ${project-} \
-p:ContinuousIntegrationBuild=true \
-p:Deterministic=true \
--runtime "@runtimeId@" \
Expand Down Expand Up @@ -43,7 +43,7 @@ EOF
find -name paket.dependencies -exec sed -i 's+source .*+source @nugetSource@/lib+g' {} \;
find -name paket.lock -exec sed -i 's+remote:.*+remote: @nugetSource@/lib+g' {} \;

env dotnet tool restore --add-source "@nugetSource@/lib"
dotnet tool restore --add-source "@nugetSource@/lib"

(( "${#projectFile[@]}" == 0 )) && dotnetRestore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dotnetInstallHook() {
runtimeIdFlags+=("--runtime @runtimeId@")
fi

env dotnet publish ${project-} \
dotnet publish ${project-} \
-p:ContinuousIntegrationBuild=true \
-p:Deterministic=true \
--output "${installPath-$out/lib/$pname}" \
Expand All @@ -40,7 +40,7 @@ dotnetInstallHook() {

dotnetPack() {
local -r project="${1-}"
env dotnet pack ${project-} \
dotnet pack ${project-} \
-p:ContinuousIntegrationBuild=true \
-p:Deterministic=true \
--output "$out/share" \
Expand Down

0 comments on commit f17d1f9

Please sign in to comment.