Unverified Commit b5447275 authored by David McFarland's avatar David McFarland Committed by GitHub
Browse files

Merge pull request #313005 from tie/dotnet-cross

buildDotnetModule: fix structured attributes support
parents aad2e77f f7d8046f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ buildDotnetModule rec {
  doCheck = true;

  preBuild = ''
    export projectFile=(ArchiSteamFarm)
    dotnetProjectFiles=(ArchiSteamFarm)
  '';

  preInstall = ''
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ buildDotnetModule (args // {
    ] ++ (nugetDeps fetchNuGet);
  };

  projectFile = "";
  dotnetGlobalTool = true;

  useDotnetFromEnv = true;

+24 −12
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@
, disabledTests ? [ ]
  # The project file to run unit tests against. This is usually referenced in the regular project file, but sometimes it needs to be manually set.
  # It gets restored and build, but not installed. You may need to regenerate your nuget lockfile after setting this.
, testProjectFile ? ""
, testProjectFile ? null

  # The type of build to perform. This is passed to `dotnet` with the `--configuration` flag. Possible values are `Release`, `Debug`, etc.
, buildType ? "Release"
@@ -88,17 +88,18 @@
} @ args:

let
  projectFiles =
    lib.optionals (projectFile != null) (lib.toList projectFile);
  testProjectFiles =
    lib.optionals (testProjectFile != null) (lib.toList testProjectFile);

  platforms =
    if args ? meta.platforms
    then lib.intersectLists args.meta.platforms dotnet-sdk.meta.platforms
    else dotnet-sdk.meta.platforms;

  inherit (callPackage ./hooks {
    inherit dotnet-sdk disabledTests nuget-source dotnet-runtime runtimeDeps buildType;
    runtimeId =
      if runtimeId != null
      then runtimeId
      else dotnetCorePackages.systemToDotnetRid stdenvNoCC.targetPlatform.system;
    inherit dotnet-sdk dotnet-runtime;
  }) dotnetConfigureHook dotnetBuildHook dotnetCheckHook dotnetInstallHook dotnetFixupHook;

  localDeps =
@@ -143,6 +144,19 @@ let
  nugetDepsFile = _nugetDeps.sourceFile;
in
stdenvNoCC.mkDerivation (args // {
  dotnetInstallPath = installPath;
  dotnetExecutables = executables;
  dotnetBuildType = buildType;
  dotnetProjectFiles = projectFiles;
  dotnetTestProjectFiles = testProjectFiles;
  dotnetDisabledTests = disabledTests;
  dotnetRuntimeId = runtimeId;
  nugetSource = nuget-source;
  dotnetRuntimeDeps = map lib.getLib runtimeDeps;
  dotnetSelfContainedBuild = selfContainedBuild;
  dotnetUseAppHost = useAppHost;
  inherit useDotnetFromEnv;

  nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [
    dotnetConfigureHook
    dotnetBuildHook
@@ -172,7 +186,7 @@ stdenvNoCC.mkDerivation (args // {
       else [ ]));

  makeWrapperArgs = args.makeWrapperArgs or [ ] ++ [
    "--prefix LD_LIBRARY_PATH : ${dotnet-sdk.icu}/lib"
    "--prefix" "LD_LIBRARY_PATH" ":" "${dotnet-sdk.icu}/lib"
  ];

  # Stripping breaks the executable
@@ -181,8 +195,6 @@ stdenvNoCC.mkDerivation (args // {
  # gappsWrapperArgs gets included when wrapping for dotnet, as to avoid double wrapping
  dontWrapGApps = args.dontWrapGApps or true;

  inherit selfContainedBuild useAppHost useDotnetFromEnv;

  # propagate the runtime sandbox profile since the contents apply to published
  # executables
  propagatedSandboxProfile = toString dotnet-runtime.__propagatedSandboxProfile;
@@ -267,11 +279,11 @@ stdenvNoCC.mkDerivation (args // {
                --no-cache \
                --force \
                ${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \
                ${lib.optionalString (flags != []) (toString flags)}
                ${lib.escapeShellArgs flags}
        }

        declare -a projectFiles=( ${toString (lib.toList projectFile)} )
        declare -a testProjectFiles=( ${toString (lib.toList testProjectFile)} )
        declare -a projectFiles=( ${lib.escapeShellArgs projectFiles} )
        declare -a testProjectFiles=( ${lib.escapeShellArgs testProjectFiles} )

        export DOTNET_NOLOGO=1
        export DOTNET_CLI_TELEMETRY_OPTOUT=1
+8 −28
Original line number Diff line number Diff line
@@ -4,28 +4,21 @@
, coreutils
, zlib
, openssl
, callPackage
, makeSetupHook
, makeWrapper
, dotnetCorePackages
  # Passed from ../default.nix
, dotnet-sdk
, disabledTests
, nuget-source
, dotnet-runtime
, runtimeDeps
, buildType
, runtimeId
}:
assert (builtins.isString runtimeId);

let
  libraryPath = lib.makeLibraryPath runtimeDeps;
  runtimeId = dotnetCorePackages.systemToDotnetRid stdenv.hostPlatform.system;
in
{
  dotnetConfigureHook = makeSetupHook
    {
      name = "dotnet-configure-hook";
      substitutions = {
        nugetSource = nuget-source;
        runtimeId = lib.escapeShellArg runtimeId;
        dynamicLinker = "${stdenv.cc}/nix-support/dynamic-linker";
        libPath = lib.makeLibraryPath [
          stdenv.cc.cc.lib
@@ -34,7 +27,6 @@ in
          zlib
          openssl
        ];
        inherit runtimeId;
      };
    }
    ./dotnet-configure-hook.sh;
@@ -43,7 +35,7 @@ in
    {
      name = "dotnet-build-hook";
      substitutions = {
        inherit buildType runtimeId;
        runtimeId = lib.escapeShellArg runtimeId;
      };
    }
    ./dotnet-build-hook.sh;
@@ -52,15 +44,7 @@ in
    {
      name = "dotnet-check-hook";
      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}"
          );
        runtimeId = lib.escapeShellArg runtimeId;
      };
    }
    ./dotnet-check-hook.sh;
@@ -69,7 +53,7 @@ in
    {
      name = "dotnet-install-hook";
      substitutions = {
        inherit buildType runtimeId;
        runtimeId = lib.escapeShellArg runtimeId;
      };
    }
    ./dotnet-install-hook.sh;
@@ -79,11 +63,7 @@ in
      name = "dotnet-fixup-hook";
      substitutions = {
        dotnetRuntime = dotnet-runtime;
        runtimeDeps = libraryPath;
        shell = stdenv.shell;
        which = "${which}/bin/which";
        dirname = "${coreutils}/bin/dirname";
        realpath = "${coreutils}/bin/realpath";
        wrapperPath = lib.makeBinPath [ which coreutils ];
      };
    }
    ./dotnet-fixup-hook.sh;
+46 −30
Original line number Diff line number Diff line
# inherit arguments from derivation
dotnetBuildFlags=( ${dotnetBuildFlags[@]-} )

dotnetBuildHook() {
    echo "Executing dotnetBuildHook"

    runHook preBuild

    if [ "${enableParallelBuilding-}" ]; then
    local -r hostRuntimeId=@runtimeId@
    local -r dotnetBuildType="${dotnetBuildType-Release}"
    local -r dotnetRuntimeId="${dotnetRuntimeId-$hostRuntimeId}"

    if [[ -n $__structuredAttrs ]]; then
        local dotnetProjectFilesArray=( "${dotnetProjectFiles[@]}" )
        local dotnetTestProjectFilesArray=( "${dotnetTestProjectFiles[@]}" )
        local dotnetFlagsArray=( "${dotnetFlags[@]}" )
        local dotnetBuildFlagsArray=( "${dotnetBuildFlags[@]}" )
    else
        local dotnetProjectFilesArray=($dotnetProjectFiles)
        local dotnetTestProjectFilesArray=($dotnetTestProjectFiles)
        local dotnetFlagsArray=($dotnetFlags)
        local dotnetBuildFlagsArray=($dotnetBuildFlags)
    fi

    if [[ -n "${enableParallelBuilding-}" ]]; then
        local -r maxCpuFlag="$NIX_BUILD_CORES"
        local -r parallelBuildFlag="true"
    else
@@ -14,50 +27,53 @@ dotnetBuildHook() {
        local -r parallelBuildFlag="false"
    fi

    if [ "${selfContainedBuild-}" ]; then
        dotnetBuildFlags+=("-p:SelfContained=true")
    if [[ -n ${dotnetSelfContainedBuild-} ]]; then
        dotnetBuildFlagsArray+=("-p:SelfContained=true")
    else
        dotnetBuildFlags+=("-p:SelfContained=false")
        dotnetBuildFlagsArray+=("-p:SelfContained=false")
    fi

    if [ "${useAppHost-}" ]; then
        dotnetBuildFlags+=("-p:UseAppHost=true")
    if [[ -n ${dotnetUseAppHost-} ]]; then
        dotnetBuildFlagsArray+=("-p:UseAppHost=true")
    fi

    local versionFlags=()
    if [ "${version-}" ]; then
        versionFlags+=("-p:InformationalVersion=${version-}")
    local versionFlagsArray=()
    if [[ -n ${version-} ]]; then
        versionFlagsArray+=("-p:InformationalVersion=$version")
    fi

    if [ "${versionForDotnet-}" ]; then
        versionFlags+=("-p:Version=${versionForDotnet-}")
    if [[ -n ${versionForDotnet-} ]]; then
        versionFlagsArray+=("-p:Version=$versionForDotnet")
    fi

    dotnetBuild() {
        local -r project="${1-}"
        local -r projectFile="${1-}"

        runtimeIdFlags=()
        if [[ "$project" == *.csproj ]] || [ "${selfContainedBuild-}" ]; then
            runtimeIdFlags+=("--runtime @runtimeId@")
        local runtimeIdFlagsArray=()
        if [[ $projectFile == *.csproj || -n ${dotnetSelfContainedBuild-} ]]; then
            runtimeIdFlagsArray+=("--runtime" "$dotnetRuntimeId")
        fi

        dotnet build ${project-} \
            -maxcpucount:$maxCpuFlag \
            -p:BuildInParallel=$parallelBuildFlag \
        dotnet build ${1+"$projectFile"} \
            -maxcpucount:"$maxCpuFlag" \
            -p:BuildInParallel="$parallelBuildFlag" \
            -p:ContinuousIntegrationBuild=true \
            -p:Deterministic=true \
            --configuration "@buildType@" \
            --configuration "$dotnetBuildType" \
            --no-restore \
            ${versionFlags[@]} \
            ${runtimeIdFlags[@]} \
            ${dotnetBuildFlags[@]}  \
            ${dotnetFlags[@]}
            "${versionFlagsArray[@]}" \
            "${runtimeIdFlagsArray[@]}" \
            "${dotnetBuildFlagsArray[@]}" \
            "${dotnetFlagsArray[@]}"
    }

    (( "${#projectFile[@]}" == 0 )) && dotnetBuild
    if (( ${#dotnetProjectFilesArray[@]} == 0 )); then
        dotnetBuild
    fi

    for project in ${projectFile[@]} ${testProjectFile[@]-}; do
        dotnetBuild "$project"
    local projectFile
    for projectFile in "${dotnetProjectFilesArray[@]}" "${dotnetTestProjectFilesArray[@]}"; do
        dotnetBuild "$projectFile"
    done

    runHook postBuild
@@ -65,6 +81,6 @@ dotnetBuildHook() {
    echo "Finished dotnetBuildHook"
}

if [[ -z "${dontDotnetBuild-}" && -z "${buildPhase-}" ]]; then
if [[ -z ${dontDotnetBuild-} && -z ${buildPhase-} ]]; then
    buildPhase=dotnetBuildHook
fi
Loading