Skip to content

Make build scripts' -help information more helpful #37377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 9, 2020
Merged

Make build scripts' -help information more helpful #37377

merged 8 commits into from
Jun 9, 2020

Conversation

ivdiazsa
Copy link
Contributor

@ivdiazsa ivdiazsa commented Jun 4, 2020

Fixes #33167.

This PR slightly changes the layout and information shown when asking for help to runtime's build scripts. The following changes were made:

  • Flags were sorted alphabetically, as most command-line tools do.
  • Short flags are now shown right next to their long counterparts.
  • Added the default values (if any) when a flag is omitted.
  • Added a few simple examples at the end.
  • Added a special handler when requesting -subset help. This is to optimize and avoid passing unnecessary data as this command does not want to trigger any build. Also, it adds a specific flag to prevent MSBuild from showing build metrics in this case.
  • Reformatted the lines a bit for better readability on smaller terminals/larger fonts.

These changes were applied to both, build.cmd and build.sh.

In addition to these changes, the "error" message shown when requesting -subset help was reworded to reassure the user it is not an error as such. The reason this mechanism is kept, is that since subset information is printed directly by MSBuild, there needs to be a way to stop it right after showing the subsets' descriptions. If we remove this, then restore finishes doing its thing and the descriptions are printed thrice. We don't want to spam the user either. If -restore is removed from the MSBuild command, it fails unless the build script has invoked restore in the past. This would cause an unknown error to appear when working with a clean repository, which is fairly often.

@ghost
Copy link

ghost commented Jun 4, 2020

Tagging subscribers to this area: @ViktorHofer
Notify danmosemsft if you want to be subscribed.

@danmoseley
Copy link
Member

Can you please paste in the new output so we can see what it looks like?

@safern safern requested a review from a team June 4, 2020 01:13
else
passedSubset="$(echo "$2" | awk '{print tolower($0)}')"
Copy link
Member

Choose a reason for hiding this comment

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

We also have detection on the first argument to parse it as a subset: https://github.com/dotnet/runtime/pull/37377/files#diff-75d32cbca8eddea951ce0484aa996d8fR130

So we also need to consider the case where people passes down:

.\build.sh help

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just tested it. It works and shows the new subset message, but it shows the metrics. Let me add a handler for that case as well.

@ivdiazsa
Copy link
Contributor Author

ivdiazsa commented Jun 4, 2020

Can you please paste in the new output so we can see what it looks like?

Sure, here are the outputs:

  • New Subset Help Message
\runtime\eng\SubsetValidation.targets(42,5): error : This is not an error. These are the available subsets. You can choose one or none at all for a full build. [C:\Git\runtime\Build.proj]
  • Build.cmd
Common settings:
  -arch (-a)                     Build platform: x86, x64, arm, arm64, or wasm.
                                 Pass a comma-separated list to build for multiple architectures.
                                 [Default: Your machine's architecture.]
  -binaryLog (-bl)               Output binary log.
  -configuration (-c)            Build configuration: Debug, Release or [CoreCLR]Checked.
                                 Pass a comma-separated list to build for multiple configurations.
                                 [Default: Debug]
  -help (-h)                     Print help and exit.
  -librariesConfiguration (-lc)  Libraries build configuration: Debug or Release.
                                 [Default: Debug]
  -os                            Build operating system: Windows_NT, Linux, OSX, or Browser.
                                 [Default: Your machine's OS.]
  -runtimeConfiguration (-rc)    Runtime build configuration: Debug, Release or [CoreCLR]Checked.
                                 [Default: Debug]
  -subset (-s)                   Build a subset, print available subsets with -subset help.
                                 '-subset' can be omitted if the subset is given as the first argument.
                                 [Default: Builds the entire repo.]
  -verbosity (-v)                MSBuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].
                                 [Default: Minimal]
  -vs                            Open the solution with VS using the locally acquired SDK. Path or solution name.
                                 (Example: -vs Microsoft.CSharp)

Actions (defaults to -restore -build):
  -build (-b)             Build all source projects.
  -clean                  Clean the solution.
  -pack                   Package build outputs into NuGet packages.
  -publish                Publish artifacts (e.g. symbols).
  -rebuild                Rebuild all source projects.
  -restore                Restore dependencies.
  -sign                   Sign build outputs.
  -test (-t)              Build and run tests.

Libraries settings:
  -allconfigurations      Build packages for all build configurations.
  -coverage               Collect code coverage when testing.
  -framework (-f)         Build framework: net5.0 or net472.
  -testnobuild            Skip building tests when invoking -test.
  -testscope              Scope tests, allowed values: innerloop, outerloop, all.

Command-line arguments not listed above are passed through to MSBuild.
The above arguments can be shortened as much as to be unambiguous.
(Example: -con for configuration, -t for test, etc.).

Here are some quick examples:

Build CoreCLR on Windows for x64 on release configuration:
.\build.cmd clr -os Windows_NT -arch x64 -configuration Release

Cross-compile CoreCLR runtime on Windows for ARM64.
.\build.cmd -subset clr.runtime -os Windows_NT -arch arm64 -configuration Release

Build Debug libraries with a Release runtime.
.\build.cmd -subset clr+libs -os Windows_NT -arch x64 -runtimeConfiguration Release

For more information, check out https://github.com/dotnet/runtime/blob/master/docs/workflow/README.md
  • Build.sh
Common settings:
  --arch                          Build platform: x86, x64, arm, armel, arm64 or wasm.
                                  [Default: Your machine's architecture.]
  --binaryLog (-bl)               Output binary log.
  --cross                         Optional argument to signify cross compilation.
  --configuration (-c)            Build configuration: Debug, Release or [CoreCLR]Checked.
                                  [Default: Debug]
  --help (-h)                     Print help and exit.
  --librariesConfiguration (-lc)  Libraries build configuration: Debug or Release.
                                  [Default: Debug]
  --os                            Build operating system: Windows_NT, Linux, FreeBSD, OSX, tvOS, iOS, Android, Browser, NetBSD or SunOS.
                                  [Default: Your machine's OS.]
  --projects <value>              Project or solution file(s) to build.
  --runtimeConfiguration (-rc)    Runtime build configuration: Debug, Release or [CoreCLR]Checked.
                                  [Default: Debug]
  --subset (-s)                   Build a subset, print available subsets with -subset help.
                                 '--subset' can be omitted if the subset is given as the first argument.
                                  [Default: Builds the entire repo.]
  --verbosity (-v)                MSBuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].
                                  [Default: Minimal]

Actions (defaults to --restore --build):
  --build (-b)               Build all source projects.
  --clean                    Clean the solution.
  --pack                     Package build outputs into NuGet packages.
  --publish                  Publish artifacts (e.g. symbols).
  --rebuild                  Rebuild all source projects.
  --restore (-r)             Restore dependencies.
  --sign                     Sign build outputs.
  --test (-t)                Build and run tests.

Libraries settings:
  --allconfigurations        Build packages for all build configurations.
  --coverage                 Collect code coverage when testing.
  --framework (-f)           Build framework: net5.0 or net472.
  --testnobuild              Skip building tests when invoking -test.
  --testscope                Test scope, allowed values: innerloop, outerloop, all.

Native build settings:
  --clang                    Optional argument to build using clang in PATH (default).
  --clangx.y                 Optional argument to build using clang version x.y.
  --cmakeargs                User-settable additional arguments passed to CMake.
  --gcc                      Optional argument to build using gcc in PATH (default).
  --gccx.y                   Optional argument to build using gcc version x.y.

Command line arguments starting with '/p:' are passed through to MSBuild.
Arguments can also be passed in with a single hyphen.

Here are some quick examples:

Build CoreCLR on Linux for x64 on release configuration:
./build.sh clr --os linux --arch x64 --configuration release

Build Debug libraries with a Release runtime.
./build.sh --subset clr+libs --os linux --arch x64 --runtimeConfiguration release

Cross-compile CoreCLR runtime on Linux for ARM64.
./build.sh -subset clr.runtime --os linux --arch arm64 --configuration release --cross

However, for this last example, you need to already have ROOTFS_DIR set up.
Further information on this can be found here:
https://github.com/dotnet/runtime/blob/master/docs/workflow/building/coreclr/linux-instructions.md

For more general information, check out https://github.com/dotnet/runtime/blob/master/docs/workflow/README.md

Copy link
Contributor

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

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

This is a big improvement; thanks.

@danmoseley
Copy link
Member

Thank you for adding examples. We have gotten a lot of feedback that it's too hard to figure out how to build. I often have to go back to the docs and I'm just copy/pasting examples from there. Whenever a command line tool has this many parameters and concepts, examples are super valuable. Are there any other common use cases it's worth adding examples for? I think it's fine to have more.

eng/build.sh Outdated
echo "Build CoreCLR on Linux for x64 on release configuration:"
echo "./build.sh clr --os linux --arch x64 --configuration release"
echo ""
echo "Build Debug libraries with a Release runtime."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
echo "Build Debug libraries with a Release runtime."
echo "Build Debug libraries for Linux with a Release runtime."

echo ""
echo "Build Debug libraries with a Release runtime."
echo "./build.sh --subset clr+libs --os linux --arch x64 --runtimeConfiguration release"
echo ""
Copy link
Member

Choose a reason for hiding this comment

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

How about adding build -subset clr+libs -runtimeConfiguration Release (it's what we suggest for library work in docs\workflow\building\libraries\README.md)

Copy link
Member

Choose a reason for hiding this comment

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

And note that that one picks the same target platform you are building on

Copy link
Member

Choose a reason for hiding this comment

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

FWIW the shortest form (that most of us use) is build clr+libs -rc Release.

eng/build.sh Outdated
echo " --clang Optional argument to build using clang in PATH (default)"
echo " --clangx.y Optional argument to build using clang version x.y"
echo " --clang Optional argument to build using clang in PATH (default)."
echo " --clangx.y Optional argument to build using clang version x.y."
Copy link
Member

Choose a reason for hiding this comment

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

Can you add an example, eg., (e.g., --clang11.0) (is that right?)

Copy link
Member

Choose a reason for hiding this comment

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

Same for gcc

Copy link
Member

Choose a reason for hiding this comment

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

--clang11.0 would not be a good example, clang versions from 7 on use only major version numbers. So we could put in e.g. --clang9
Which actually reveals that the help is slightly incorrect.

Copy link
Member

Choose a reason for hiding this comment

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

@ivdiazsa I think this is still wrong? sounds like it should be --clangx ?

eng/build.sh Outdated
echo "Cross-compile CoreCLR runtime on Linux for ARM64."
echo "./build.sh -subset clr.runtime --os linux --arch arm64 --configuration release --cross"
echo ""
echo "However, for this last example, you need to already have ROOTFS_DIR set up."
Copy link
Member

Choose a reason for hiding this comment

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

more examples (5? ) would be great -- eg., a mono one.

eng/build.ps1 Outdated
Comment on lines 90 to 91
$argumentsForHelp = "-restore -build /p:subset=help /clp:nosummary"
Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $argumentsForHelp"
Copy link
Member

Choose a reason for hiding this comment

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

nit: inline $argumentsForHelp into the Invoke-Expression statement.

eng/build.sh Outdated
Comment on lines 111 to 112
argumentsForHelp="-restore -build /p:subset=help /clp:nosummary"
"$scriptroot/common/build.sh" $argumentsForHelp
Copy link
Member

Choose a reason for hiding this comment

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

Same comment about inlining.

eng/build.ps1 Outdated
Write-Host " Pass a comma-separated list to build for multiple architectures."
Write-Host " [Default: Your machine's architecture.]"
Write-Host " -binaryLog (-bl) Output binary log."
Write-Host " -configuration (-c) Build configuration: Debug, Release or [CoreCLR]Checked."
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't casing matter (at least on Unix)? @safern should it be consistently lower case or upper? We should note that in the help, and fix the help.

Copy link
Member

Choose a reason for hiding this comment

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

The casing doesn't matter as we are upper-casing passed-in configurations in the scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. In a previous PR I made (35642) it no longer matters if you pass --os LINUX or --os linux. It gets handled internally and converted to the casing MSBuild expects.

Copy link
Member

Choose a reason for hiding this comment

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

consistently using lower case in examples seems better but I can't put my finger on why so it's probably just me :)

eng/build.ps1 Outdated
Write-Host ".\build.cmd -subset clr.runtime -os Windows_NT -arch arm64 -configuration Release"
Write-Host ""
Write-Host "Build Debug libraries with a Release runtime."
Write-Host ".\build.cmd -subset clr+libs -os Windows_NT -arch x64 -runtimeConfiguration Release"
Copy link
Member

Choose a reason for hiding this comment

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

This is super verbose and I don't know anyone specifying the defaults for OS and Arch.

Suggested change
Write-Host ".\build.cmd -subset clr+libs -os Windows_NT -arch x64 -runtimeConfiguration Release"
Write-Host ".\build.cmd clr+libs -rc Release"

Copy link
Member

Choose a reason for hiding this comment

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

I agree, I never specify -os or -arch explicitly.

Copy link
Member

Choose a reason for hiding this comment

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

I mean, I do specify arch sometime when I want to do a cross build, but it is very rare.

Copy link
Contributor

Choose a reason for hiding this comment

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

I often specify arch when building on Windows x64 to build arm/arm64/x86.

One thing that is very confusing to me is: when do I need to specify -cross?

Copy link
Contributor Author

@ivdiazsa ivdiazsa Jun 4, 2020

Choose a reason for hiding this comment

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

From what the docs say and my past experiences, --cross is a flag specified when you are doing a cross-build, like building for ARM64 on x64. Worth mentioning it's only necessary on Unix (i.e. build.sh)

eng/build.ps1 Outdated
Write-Host " [Default: Builds the entire repo.]"
Write-Host " -verbosity (-v) MSBuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]."
Write-Host " [Default: Minimal]"
Write-Host " -vs Open the solution with VS using the locally acquired SDK. Path or solution name."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Write-Host " -vs Open the solution with VS using the locally acquired SDK. Path or solution name."
Write-Host " -vs Open the solution with Visual Studio using the locally acquired SDK. Path or solution name."

Does this work with .csproj or only .sln @ViktorHofer ?

Copy link
Member

Choose a reason for hiding this comment

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

You can use it to open anything that works inside VS :)

Copy link
Member

Choose a reason for hiding this comment

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

OK then we should say solution or project file.

Write-Host " -allconfigurations Build packages for all build configurations"
Write-Host " -allconfigurations Build packages for all build configurations."
Write-Host " -coverage Collect code coverage when testing."
Write-Host " -framework (-f) Build framework: net5.0 or net472."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Write-Host " -framework (-f) Build framework: net5.0 or net472."
Write-Host " -framework (-f) Target framework: net5.0 or net472. Defaults to net5.0."

Write-Host " -sign Sign build outputs"
Write-Host " -publish Publish artifacts (e.g. symbols)"
Write-Host " -clean Clean the solution"
Write-Host " -build (-b) Build all source projects."
Copy link
Member

@danmoseley danmoseley Jun 4, 2020

Choose a reason for hiding this comment

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

Suggested change
Write-Host " -build (-b) Build all source projects."
Write-Host " -build (-b) Build all source projects. (Assumes you already ran -restore)"

I made this mistake in the past

Write-Host " -build (-b) Build all source projects."
Write-Host " -clean Clean the solution."
Write-Host " -pack Package build outputs into NuGet packages."
Write-Host " -publish Publish artifacts (e.g. symbols)."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Write-Host " -publish Publish artifacts (e.g. symbols)."
Write-Host " -publish Publish artifacts (e.g. symbols - assumes you already ran -build)."

eng/build.ps1 Outdated
Write-Host " -rebuild Rebuild all source projects."
Write-Host " -restore Restore dependencies."
Write-Host " -sign Sign build outputs."
Write-Host " -test (-t) Build and run tests."
Copy link
Member

Choose a reason for hiding this comment

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

Does this actually build tests, or just run?
Also, does it build the library under test, or just the test library?

good to note this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an interesting observation and something worth including. I believe it just builds the test library, but I've not used it much so I'm not sure. Can you clarify this @janvorli?

Copy link
Member

Choose a reason for hiding this comment

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

the target test just runs the tests. In order to build you need to do -build and passing the right subset that includes tests.

Copy link
Member

Choose a reason for hiding this comment

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

The -test switch incrementally restores and builds the test projects. You can specify -test -testnobuild to only run the tests.

runtime/eng/build.ps1

Lines 108 to 113 in 6176924

# Check if an action is passed in
$actions = "b","build","r","restore","rebuild","sign","testnobuild","publish","clean"
$actionPassedIn = @(Compare-Object -ReferenceObject @($PSBoundParameters.Keys) -DifferenceObject $actions -ExcludeDifferent -IncludeEqual).Length -ne 0
if ($null -ne $properties -and $actionPassedIn -ne $true) {
$actionPassedIn = @(Compare-Object -ReferenceObject $properties -DifferenceObject $actions.ForEach({ "-" + $_ }) -ExcludeDifferent -IncludeEqual).Length -ne 0
}

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for clarifying!

@danmoseley
Copy link
Member

Thanks for doing this, one thing already clear from the community survey is that build is intimidating, and good help text has to help.

@BruceForstall
Copy link
Contributor

One thing that it would be useful to describe in more detail, although in the documentation on GitHub and not in this help message, is the difference between -c, -lc, and -rc. It seems to me there are more subtleties here than are obvious: I always assumed that -c give the "default" and -lc/-rc overrides it, or that you could provide both -lc/-rc and not -c and it would be fine because nothing would use the value from -c, but I think that's not actually correct.

@ivdiazsa
Copy link
Contributor Author

ivdiazsa commented Jun 4, 2020

One thing that it would be useful to describe in more detail, although in the documentation on GitHub and not in this help message, is the difference between -c, -lc, and -rc. It seems to me there are more subtleties here than are obvious: I always assumed that -c give the "default" and -lc/-rc overrides it, or that you could provide both -lc/-rc and not -c and it would be fine because nothing would use the value from -c, but I think that's not actually correct.

I agree with this. It is not clear what are the implications of using each one, and under which scenarios somebody would use one or the other. I would gladly make this change but I'd need some guidance on how these flags work :)

@ViktorHofer
Copy link
Member

ViktorHofer commented Jun 4, 2020

but I'd need some guidance on how these flags work :)

As @BruceForstall described, passing in a configuration via -configuration/-c sets the base configuration which can either be Debug/Release or for CoreCLR Checked. If you specify -runtimeconfiguration/-rc, you control the configuration for the runtime projects (mono & coreclr) and it wins over the passed in configuration with the -configuration/-c switch. Same for -librariesconfiguration/-lc for libraries.

So specifying build clr+libs -rc Debug -c Release means that you will build the runtime projects (coreclr in this case) with Debug and everything else with Release (in this case only libs).

@ivdiazsa
Copy link
Contributor Author

ivdiazsa commented Jun 4, 2020

Thank you very much to everyone for the feedback on this! Now I have a clearer picture on the most common use cases for these build scripts, and how they work. I will recap the proposed changes in the following list, and please let me know if I missed something.

Changes to be done:

  • Make the examples less verbose (i.e. use short flags and omit os and arch in those where there is no cross-building involved.
  • Rephrase/clarify some wording:
    • Change Build OS to Target OS.
    • Specify Checked is only for CoreCLR.
    • Specify assumptions for certain flags (e.g. -publish assumes -build has been run).
    • Add missing defaults (e.g. -f defaults to net5.0).
    • Other small changes like using "for Linux" instead of "on Linux" and changing "VS" to "Visual Studio".
  • Inline help command-line arguments.
  • Add more examples:
    • Using --clang.
    • Using --gcc.
    • One on building Mono.
  • Handle special case ./build.sh help, which is assumed to be ./build.sh --subset help.

@danmoseley
Copy link
Member

It would be great to see the updated output before we merge.

@BruceForstall
Copy link
Contributor

BruceForstall commented Jun 4, 2020

@ViktorHofer

So specifying build clr+libs -rc Debug -c Release means that you will build the runtime projects (coreclr in this case) with Debug and everything else with Release (in this case only libs).

so do all of the following do the same thing?

build clr+libs+libs.tests -rc Debug -c Release
build clr+libs+libs.tests -c Debug -lc Release
build clr+libs+libs.tests -rc Debug -lc Release

@safern
Copy link
Member

safern commented Jun 4, 2020

so do all of the following do the same thing?

Correct.

@ivdiazsa
Copy link
Contributor Author

ivdiazsa commented Jun 5, 2020

Here are the new updated versions of the help messages (updated with Bruce's latest observations):

  • Build.cmd
Common settings:
  -arch (-a)                     Target platform: x86, x64, arm, arm64, or wasm.
                                 Pass a comma-separated list to build for multiple architectures.
                                 [Default: Your machine's architecture.]
  -binaryLog (-bl)               Output binary log.
  -configuration (-c)            Build configuration: Debug, Release or Checked.
                                 Checked is exclusive to the CLR subset. It is the same as Debug, except code is
                                 compiled with optimizations enabled.
                                 Pass a comma-separated list to build for multiple configurations.
                                 [Default: Debug]
  -help (-h)                     Print help and exit.
  -librariesConfiguration (-lc)  Libraries build configuration: Debug or Release.
                                 [Default: Debug]
  -os                            Target operating system: Windows_NT, Linux, OSX, or Browser.
                                 [Default: Your machine's OS.]
  -runtimeConfiguration (-rc)    Runtime build configuration: Debug, Release or Checked.
                                 Checked is exclusive to the CLR runtime. It is the same as Debug, except code is
                                 compiled with optimizations enabled.
                                 [Default: Debug]
  -subset (-s)                   Build a subset, print available subsets with -subset help.
                                 '-subset' can be omitted if the subset is given as the first argument.
                                 [Default: Builds the entire repo.]
  -verbosity (-v)                MSBuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].
                                 [Default: Minimal]
  -vs                            Open the solution with Visual Studio using the locally acquired SDK.
                                 Path or any project or solution name is accepted.
                                 (Example: -vs Microsoft.CSharp)

Actions (defaults to -restore -build):
  -build (-b)             Build all source projects.
                          This assumes -restore has been run already.
  -clean                  Clean the solution.
  -pack                   Package build outputs into NuGet packages.
  -publish                Publish artifacts (e.g. symbols).
                          This assumes -build has been run already.
  -rebuild                Rebuild all source projects.
  -restore                Restore dependencies.
  -sign                   Sign build outputs.
  -test (-t)              Incrementally builds and runs tests.
                          Use in conjuction with -testnobuild to only run tests.

Libraries settings:
  -allconfigurations      Build packages for all build configurations.
  -coverage               Collect code coverage when testing.
  -framework (-f)         Build framework: net5.0 or net472.
                          [Default: net5.0]
  -testnobuild            Skip building tests when invoking -test.
  -testscope              Scope tests, allowed values: innerloop, outerloop, all.

Command-line arguments not listed above are passed through to MSBuild.
The above arguments can be shortened as much as to be unambiguous.
(Example: -con for configuration, -t for test, etc.).

Here are some quick examples. These assume you are on a Windows x64 machine:

* Build CoreCLR for Windows x64 on Release configuration:
.\build.cmd clr -c release

* Cross-compile CoreCLR runtime for Windows ARM64 on Release configuration.
.\build.cmd clr.runtime -arch arm64 -c release

* Build Debug libraries with a Release runtime for Windows x64.
.\build.cmd clr+libs -rc release

* Build Release libraries and their tests with a Checked runtime for Windows x64, and run the tests.
.\build.cmd clr+libs+libs.tests -rc checked -lc release -test

* Build Mono runtime for Windows x64 on Release configuration.
.\build.cmd mono -c release

It's important to mention that to build Mono for the first time,
you need to build the CLR and Libs subsets beforehand.
This is done automatically if a full build is performed at first.

For more information, check out https://github.com/dotnet/runtime/blob/master/docs/workflow/README.md
  • Build.sh
Common settings:
  --arch                          Target platform: x86, x64, arm, armel, arm64 or wasm.
                                  [Default: Your machine's architecture.]
  --binaryLog (-bl)               Output binary log.
  --cross                         Optional argument to signify cross compilation.
  --configuration (-c)            Build configuration: Debug, Release or Checked.
                                  Checked is exclusive to the CLR subset. It is the same as Debug, except code is
                                  compiled with optimizations enabled.
                                  [Default: Debug]
  --help (-h)                     Print help and exit.
  --librariesConfiguration (-lc)  Libraries build configuration: Debug or Release.
                                  [Default: Debug]
  --os                            Target operating system: Windows_NT, Linux, FreeBSD, OSX, tvOS, iOS, Android,
                                  Browser, NetBSD or SunOS.
                                  [Default: Your machine's OS.]
  --projects <value>              Project or solution file(s) to build.
  --runtimeConfiguration (-rc)    Runtime build configuration: Debug, Release or Checked.
                                  Checked is exclusive to the CLR runtime. It is the same as Debug, except code is
                                  compiled with optimizations enabled.
                                  [Default: Debug]
  --subset (-s)                   Build a subset, print available subsets with -subset help.
                                 '--subset' can be omitted if the subset is given as the first argument.
                                  [Default: Builds the entire repo.]
  --verbosity (-v)                MSBuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].
                                  [Default: Minimal]

Actions (defaults to --restore --build):
  --build (-b)               Build all source projects.
                             This assumes --restore has been run already.
  --clean                    Clean the solution.
  --pack                     Package build outputs into NuGet packages.
  --publish                  Publish artifacts (e.g. symbols).
                             This assumes --build has been run already.
  --rebuild                  Rebuild all source projects.
  --restore (-r)             Restore dependencies.
  --sign                     Sign build outputs.
  --test (-t)                Incrementally builds and runs tests.
                             Use in conjuction with --testnobuild to only run tests.

Libraries settings:
  --allconfigurations        Build packages for all build configurations.
  --coverage                 Collect code coverage when testing.
  --framework (-f)           Build framework: net5.0 or net472.
                             [Default: net5.0]
  --testnobuild              Skip building tests when invoking -test.
  --testscope                Test scope, allowed values: innerloop, outerloop, all.

Native build settings:
  --clang                    Optional argument to build using clang in PATH (default).
  --clangx                   Optional argument to build using clang version x (used for Clang 7 and newer).
  --clangx.y                 Optional argument to build using clang version x.y (used for Clang 6 and older).
  --cmakeargs                User-settable additional arguments passed to CMake.
  --gcc                      Optional argument to build using gcc in PATH (default).
  --gccx.y                   Optional argument to build using gcc version x.y.

Command line arguments starting with '/p:' are passed through to MSBuild.
Arguments can also be passed in with a single hyphen.

Here are some quick examples. These assume you are on a Linux x64 machine:

* Build CoreCLR for Linux x64 on Release configuration:
./build.sh clr -c release

* Build Debug libraries with a Release runtime for Linux x64.
./build.sh clr+libs -rc release

* Build Release libraries and their tests with a Checked runtime for Linux x64, and run the tests.
./build.sh clr+libs+libs.tests -rc checked -lc release -test

* Build CoreCLR for Linux x64 on Debug configuration using Clang 9.
./build.sh clr -clang9

* Build CoreCLR for Linux x64 on Debug configuration using GCC 8.4.
./build.sh clr -gcc8.4

* Cross-compile CoreCLR runtime for Linux ARM64 on Release configuration.
./build.sh clr.runtime -arch arm64 -c release -cross

However, for this example, you need to already have ROOTFS_DIR set up.
Further information on this can be found here:
https://github.com/dotnet/runtime/blob/master/docs/workflow/building/coreclr/linux-instructions.md

* Build Mono runtime for Linux x64 on Release configuration.
./build.sh mono -c release

It's important to mention that to build Mono for the first time,
you need to build the CLR and Libs subsets beforehand.
This is done automatically if a full build is performed at first.

For more general information, check out https://github.com/dotnet/runtime/blob/master/docs/workflow/README.md

eng/build.ps1 Outdated
Write-Host " [Default: Your machine's architecture.]"
Write-Host " -binaryLog (-bl) Output binary log."
Write-Host " -configuration (-c) Build configuration: Debug, Release or Checked."
Write-Host " Checked is exclusive to the CLR subset. Use it for optimized code with asserts and"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is incorrect: Checked flavor also sets the DEBUG macro. The only difference between Debug and Checked flavors is that the Checked flavor is compiled with compiler and linker optimizations, so it runs faster. I would write (here and elsewhere):

Checked is exclusive to the CLR subset. It is the same as Debug, but is compiled with optimizations enabled so runs faster.

The downside of being compiled with optimizations is it is sometimes harder to debug. But we don't need to write a novel here :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see. I had misunderstood how the DEBUG macro is enabled. Thanks for the clarification!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it. I also updated the previous comment with the latest output.

@danmoseley
Copy link
Member

@stephentoub any other feedback on the output?

showSubsetHelp
exit 0
fi

arguments="$arguments /p:Subset=$1"
Copy link
Member

Choose a reason for hiding this comment

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

Now that you're touching this, should /p:Subset=$1 be /p:Subset=$opt? don't know if that'll make a difference, but it is weird to check if $opt matches the regex, if opt is == help and then use $1.

Copy link
Contributor Author

@ivdiazsa ivdiazsa Jun 5, 2020

Choose a reason for hiding this comment

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

I think you're right and using $opt would make the code look cleaner. Just before making this change, the arguments for MSBuild are not case-sensitive right? In the sense that /p:Subset=CLR would work just fine like /p:Subset=clr? Just making sure :)

Copy link
Member

Choose a reason for hiding this comment

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

IIRC it is case sensitive in Unix, but we lowercase the subsets before processing them:

<_subset Condition="'$(Subset)' != ''">+$(Subset.ToLowerInvariant())+</_subset>

Copy link
Member

@danmoseley danmoseley left a comment

Choose a reason for hiding this comment

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

LGTM except for --clangx.y seems like it should be --clangx

Thanks for improving this!

@BruceForstall
Copy link
Contributor

except for --clangx.y seems like it should be --clangx

Perhaps more clearly, --clangVERSION where VERSION is 9, 8, ... because it used to be "x.y" and now is just "x" (no minor version)?

Copy link
Member

@safern safern left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning this up!

@janvorli
Copy link
Member

janvorli commented Jun 5, 2020

LGTM except for --clangx.y seems like it should be --clangx

It depends on the clang version. Versions <= 6.0 use the x.y versioning schema, versions >=7 use just single number. LLVM has changed the versioning this way.

@ivdiazsa
Copy link
Contributor Author

ivdiazsa commented Jun 5, 2020

LGTM except for --clangx.y seems like it should be --clangx

It depends on the clang version. Versions <= 6.0 use the x.y versioning schema, versions >=7 use just single number. LLVM has changed the versioning this way.

For the sake of keeping "good historical track", I believe we should leave both in this case. I'll correct --clang to --clangx nonetheless (or would --clangVERSION be preferred?). Now that we are touching this, should --gcc be changed to --gccx as well? Or do GCC versions always use the x.y notation? @janvorli @danmosemsft

@danmoseley
Copy link
Member

do GCC versions always use the x.y notation?

don't know

@janvorli
Copy link
Member

janvorli commented Jun 6, 2020

Yes, gcc version is always x.y

@ivdiazsa ivdiazsa merged commit da97f17 into dotnet:master Jun 9, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
@ivdiazsa ivdiazsa deleted the show_time branch March 1, 2021 21:51
@ivdiazsa ivdiazsa restored the show_time branch March 1, 2021 21:51
@ivdiazsa ivdiazsa deleted the show_time branch March 1, 2021 21:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

build -help needs to be more helpful
8 participants