Merge pull request #313514 from tie/dotnet-cross-split

buildDotnetModule: fix cross-compilation and remove dotnet-test-sdk
This commit is contained in:
David McFarland 2024-05-23 14:05:46 -03:00 committed by GitHub
commit f17d1f9302
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 35 additions and 37 deletions

View File

@ -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`.

View File

@ -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:
@ -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

View File

@ -8,7 +8,6 @@
, makeSetupHook
, makeWrapper
, dotnet-sdk
, dotnet-test-sdk
, disabledTests
, nuget-source
, dotnet-runtime
@ -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";
@ -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;
@ -85,5 +85,6 @@ in
dirname = "${coreutils}/bin/dirname";
realpath = "${coreutils}/bin/realpath";
};
} ./dotnet-fixup-hook.sh) { };
}
./dotnet-fixup-hook.sh;
}

View File

@ -41,7 +41,7 @@ dotnetBuildHook() {
runtimeIdFlags+=("--runtime @runtimeId@")
fi
env dotnet build ${project-} \
dotnet build ${project-} \
-maxcpucount:$maxCpuFlag \
-p:BuildInParallel=$parallelBuildFlag \
-p:ContinuousIntegrationBuild=true \

View File

@ -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 \

View File

@ -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@" \
@ -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

View File

@ -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}" \
@ -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" \