Commit graph

30 commits

Author SHA1 Message Date
Leonard Hecker 479ef264b2
Implement basic profile matching (#11390)
This implements command line matching for `CascadiaSettings::GetProfileForArgs`.
The command lines for all user profiles are resolved to absolute file paths,
argument quotes are standardized ("canonicalized") and the results are cached.

When `GetProfileForArgs` is called with a Commandline() value, we "canonicalize"
the argument as well and find the profile that is the longest prefix.
If none could be found the default profile is returned.

## PR Checklist
* [x] Closes #9458
* [x] Closes #10952
* [x] I work here
* [ ] Tests added/passed

## Validation Steps Performed

* Open a `cmd.exe` tab in the store-version of WT
* Run `start cmd`
  --> A tab with the `cmd.exe` profile opens
* Run `start pwsh.exe`
  --> A tab with the PowerShell 7 profile opens
* Run PowerShell 7 from the start menu
  --> A tab with the PowerShell 7 profile opens
* Create a symlink for PowerShell 7 and launch `pwsh.exe` from there
  --> A tab with the PowerShell 7 profile opens
2021-10-08 00:40:10 +00:00
Michael Niksa 0a7310dee4
Adjust tools version for folks running on 2022 (#11266)
Adjust tools version for folks running on 2022

## PR Checklist
* [x] Closes annoyance that @lhecker and I have selfhosting VS2022
* [x] I work here
* [x] Solution built
* [x] @dhowett said something like "lol sure" in Teams.
2021-09-17 20:58:08 +00:00
Leonard Hecker d7f2a39aeb
Enable incremental linking for debug builds (#10342)
## Summary of the Pull Request

Incremental linking was disabled for debug builds only by mistake in the past.
It can't hurt to have it enabled for debug builds.

## PR Checklist
* [x] I work here
* [x] Project still builds
2021-06-04 23:52:49 +00:00
Leonard Hecker 5d6eec6cde
Fix compilation with VS16.10 and later (#10208)
## Summary of the Pull Request

VS16.10 and later contain two regressions:
* Marking the use of `pshpack*.h` in system headers with C4103
* The newly included, builtin `AssemblyReference.xaml` is missing the `AssemblyReferences` project capability

## PR Checklist
* [x] I work here

## Validation Steps Performed

Built the project with VS16.10 and VS17.0.
2021-05-26 20:11:38 +00:00
Dustin L. Howett 89af44488f
Emit fixup debug info for internal tooling (#10151)
See MSFT-33187224 for more information.

This may impact debuggability; I have no idea how to tell.
2021-05-24 13:33:20 +00:00
Leonard Hecker eaeab7a807
Upgrade Windows SDK to 19041 (#10118)
## Summary of the Pull Request

Upgrade the Windows SDK to 19041 by setting `WindowsTargetPlatformMinVersion` to 17763 and `WindowsTargetPlatformVersion` to 19041.

## PR Checklist
* [x] I work here
* [x] Tests added/passed

## Validation Steps Performed

General usage of the Windows Terminal application appears fine.
2021-05-20 16:04:25 +00:00
Michael Niksa 7dadde5dd6
Implement PGO in pipelines for AMD64 architecture; supply training test scenarios (#10071)
Implement PGO in pipelines for AMD64 architecture; supply training test scenarios

## References
- #3075 - Relevant to speed interests there and other linked issues.

## PR Checklist
* [x] Closes #6963
* [x] I work here.
* [x] New UIA Tests added and passed. Manual build runs also tested.

## Detailed Description of the Pull Request / Additional comments
- Creates a new pipeline run for creating instrumented binaries for Profile Guided Optimization (PGO).
- Creates a new suite of UIA tests on the full Windows Terminal app to run PGO training scenarios on instrumented binaries (and incidentally can be used to write other UIA tests later for the full Terminal app.)
- Creates a new NuGet artifact to store trained PGO databases (PGD files) at `Microsoft.Internal.Windows.Terminal.PGODatabase`
- Creates a new NuGet artifact to supply large-scale test content for automated tests at `Microsoft.Internal.Windows.Terminal.TestContent`
- Adjusts the release pipeline to run binaries in PGO optimized mode where content from PGO databases is leveraged at link time to optimize the final release build

The following binaries are trained:
- OpenConsole.exe
- WindowsTerminal.exe
- TerminalApp.dll
- TerminalConnection.dll
- Microsoft.Terminal.Control.dll
- Microsoft.Terminal.Remoting.dll
- Microsoft.Terminal.Settings.Editor.dll
- Microsoft.Terminal.Settings.Model.dll

In the future, adding `<PgoTarget>true</PgoTarget>` to a new `vcxproj` file will automatically enroll the DLL/EXE for PGO instrumentation and optimization going forward.

Two training test scenarios are implemented:
- Smoke test the Terminal by just opening it and typing a bit of text then exiting. (Should help focus on the standard launch path.)
- Optimize bulk text output by launching terminal, outputting `big.txt`, then exiting.

Additional scenarios can be contributed to the `WindowsTerminal_UIATests` project with the `[TestProperty("IsPGO", "true")]` annotation to add them to the suite of scenarios for PGO.

**NOTE:** There are currently no weights applied to the various test scenarios. We will revisit that in the future when/if necessary.

## Validation Steps Performed
- [x] - Training run completed at https://dev.azure.com/ms/terminal/_build?definitionId=492&_a=summary
- [x] - Optimization run completed locally (by forcing `PGOBuildMode` to `Optimize` on my local machine, manually retrieving the databases with NuGet, and building).
- [x] - Validated locally that x86 and ARM64 do not get trained and automatically skip optimization as databases are not present for them.
- [x] - Smoke tested optimized binary versus latest releases. `big.txt` output through CMD is ~11-12seconds prior to PGO and just over 8 seconds with PGO.
2021-05-13 21:12:30 +00:00
Dustin L. Howett 07c5735471
Move Branding into common props (#9668) 2021-03-30 18:08:53 -05:00
Dustin L. Howett 12275c8599
Add a Fuzzing configuration and a version of conhost that can be fuzzed (#9604)
This commit introduces a new build configuration, "Fuzzing", which
enables the new address sanitizer (shipped in VS 16.9) and code
coverage over the entire solution. Only a small subset of projects
(those comprising original conhost, right now) are selected to build in
this configuration, and even then only in Fuzzing|x64.

It also adds a fuzzing-adapted build of conhost, which makes no server
connections and handles no client applications. To do this, I've
replicated a bit of the console startup routine into fuzzmain.cpp and
made up some fake data. This is the bare minimum required to boot up
Win32 interactivity (or VT interactivity!) and pretend that a process
has connected.

If we don't pretend that a process has connected, "conhost" will exit
immediately. If we don't forge the process list, conhost will exit. If
we can't provide a server handle, we can't provide a "device comm".

Minor changes were necessary to server/host such that they would accept
a preexisting "device comm". We use this new behavior to provide a
"null" one that only hangs up threads and otherwise responds to requests
successfully.

This fuzzing-adapted build links LLVM's libFuzzer, which is an excellent
coverage-based fuzzer that will produce a corpus of inputs that exercise
unique codepaths. Eventually, we can use this to generate known-"good"
inputs for anything.

I've gone ahead and added a fuzz function that yeets bytes directly into
WriteCharsLegacy, which was the original reason I went down this path.

The implementation of LLVMFuzzerTestOneInput should be replaced with
whatever you want to fuzz.
2021-03-29 14:23:30 +00:00
Dustin L. Howett 691e02ef1c
Force DebugFull PDBs on all build types (#9441)
I've also taken the opportunity to kill the xxxFullPDB trick. The
intermediate PDB is allowed to remain "vc141.pdb" or whatever it wants
to be. PDBs are now simply named after their projects, as was always
tradition.
2021-03-10 23:49:03 +00:00
Dustin L. Howett 1e4c6978b7
submodule check: actually check for a real file in the repo (#9438)
Git may create folders for submodules; let's make sure they're populated.
2021-03-10 21:14:30 +00:00
Austin Lamb 539a5dc0af
Greatly reduce allocations in the conhost/OpenConsole startup path (#8489)
I was looking at conhost/OpenConsole and noticed it was being pretty
inefficient with allocations due to some usages of std::deque and
std::vector that didn't need to be done quite that way.

So this uses std::vector for the TextBuffer's storage of ROW objects,
which allows one allocation to contiguously reserve space for all the
ROWs - on Desktop this is 9001 ROW objects which means it saves 9000
allocations that the std::deque would have done.  Plus it has the
benefit of increasing locality of the ROW objects since deque is going
to chase pointers more often with its data structure.

Then, within each ROW there are CharRow and ATTR_ROW objects that use
std::vector today.  This changes them to use Boost's small_vector, which
is a variation of vector that allows for the so-called "small string
optimization."  Since we know the typical size of these vectors, we can
pre-reserve the right number of elements directly in the
CharRow/ATTR_ROW instances, avoiding any heap allocations at all for
constructing these objects.

There are a ton of variations on this "small_vector" concept out there
in the world - this one in Boost, LLVM has one called SmallVector,
Electronic Arts' STL has a small_vector, Facebook's folly library has
one...there are a silly number of these out there.  But Boost seems like
it's by far the easiest to consume in terms of integration into this
repo, the CI/CD pipeline, licensing, and stuff like that, so I went with
the boost version.

In terms of numbers, I measured the startup path of OpenConsole.exe on
my dev box for Release x64 configuration.  My box is an i7-6700k @ 4
Ghz, with 32 GB RAM, not that I think machine config matters much here:

|        | Allocation count    | Allocated bytes    | CPU usage (ms) |
| ------ | ------------------- | ------------------ | -------------- |
| Before | 29,461              | 4,984,640          | 103            |
| After  | 2,459 (-91%)        | 4,853,931 (-2.6%)  | 96 (-7%)       |

Along the way, I also fixed a dynamic initializer I happened to spot in
the registry code, and updated some docs.

## Validation Steps Performed
- Ran "runut", "runft" and "runuia" locally and confirmed results are
  the same as the main branch
- Profiled the before/after numbers in the Visual Studio profiler, for
  the numbers shown in the table

Co-authored-by: Austin Lamb <austinl@microsoft.com>
2020-12-16 10:40:30 -08:00
Michael Niksa e6aeb8a017
Use LanguageStandard over explicit compiler flag for C++17 (#8150)
Turns out there's an actual way to specify C++17 for MSBuild purposes
besides just passing the compile flag.

## References
* Future C++20 support (modules)

## PR Checklist
* [x] Closes random fact found while exploring VS16.8 preview C++20
  modules.
* [x] I work here.
* [x] It still builds.

## Detailed Description of the Pull Request / Additional comments
* We've been setting C++17 with just the flag passed to the compiler
  `cl.exe`. But it turns out that this particular `LanguageStandard`
  option will need to be set appropriately one day for us to use C++20
  modules (as evidenced by the latest VS16.8 preview that I tried out to
  explore modules.) The `AdditionalOption` alone isn't enough to ensure
  that modules can be "seen" by other projects after production, but
  `LanguageStandard` is (and will set the compiler option as appropriate
  as well as whatever internal goo that MSBuild needs to hook up other
  stuff.)

## Validation Steps Performed
* Built with it changed.
2020-11-03 15:20:48 -08:00
PankajBhojwani 2bf5d18c84
Add support for autodetecting URLs and making hyperlinks (#7691)
This pull request is the initial implementation of hyperlink auto
detection

Overall design:
- Upon startup, TerminalCore gives the TextBuffer some patterns it
  should know about
- Whenever something in the viewport changes (i.e. text
  output/scrolling), TerminalControl tells TerminalCore (through a
  throttled function for performance) to retrieve the visible pattern
  locations from the TextBuffer
- When the renderer encounters a region that is associated with a
  pattern, it paints that region differently 

References #5001
Closes #574
2020-10-28 20:24:43 +00:00
Dustin L. Howett fc9a46dbbd
Remove all our path antics; force native projects to bin/, obj/ (#8062)
This commit fixes our longstanding build artifact output issues and
finally unifies all C++ project output into bin/ and obj/.

In light of that, I've removed NoOutputRedirection.

I've also updated WTU and U8U16Test to use our common build props and
fixed any warnings/compilation errors that popped out.

I validated this change by running repeated incremental builds after
changing individual .cpp files in many of our C++/WinRT projects.
2020-10-27 15:00:41 -07:00
Dustin L. Howett (MSFT) 0741cfdaec
Enable Control Flow Guard in the common build props (#5453)
All binaries produced by our build system will have CFG enabled.

Fixes #5452
2020-04-22 11:30:13 -07:00
Dustin L. Howett (MSFT) 86685079ec
build: move oss required to build conhost out of dep/ (#5451)
This change is necessary as the dep/ folder is not synced into the
Windows source tree.

I've also added a build rule producing a lib for {fmt}.

This will be required for our next OS ingestion.
2020-04-21 14:43:09 -07:00
Mike Griese 56259ea005
Add a git submodules sanity check step to the build (#5424)
This commit adds a specific error message to the build that tells people
to restore git submodules if they forgot to read the README.

#5416 was the straw that broke the camel's back.
2020-04-20 11:11:36 -07:00
Dustin L. Howett 114e462669
Import fmtlib/fmt@6.2.0, a C++20-style format library (#5336)
We received a request from our localization team to switch from
printf-style format strings (%s, %u) to format strings with positional
argument support. I've been hoping for a long time to take a dependency
on C++20's std::format, but we're just not somewhere we can do that.
Enter fmt. fmt is _exactly_ the library we need.

Minor comparison:

std::wstring_view world = /* ... */;
auto str{ wil::str_printf<std::wstring>(L"hello %.*s",
	   gsl::narrow_cast<size_t>(world.size()),
	   world.data()) };

---

auto str{ fmt::format(L"hello {0}", world) };

If you really want to use the print specifiers:

auto str{ fmt::printf(L"hello %s", world) };

It's got optional compile-time checking for format strings and is
MIT-licensed. Eventually, we should be able to replace fmt:: with std::
and end up pretty much where we left off.
What more could you ask for?
2020-04-14 13:04:23 -07:00
Dustin L. Howett (MSFT) 48480e6998
Figure out if the x64 hosted tools make our build better or worse (#4956)
This commit may help with the compiler and linker running out of memory.
2020-03-25 15:47:17 +00:00
Michael Niksa 680577f55c
Update til::bitmap to use dynamic_bitset<> + libpopcnt (#5092)
This commit replaces `std::vector<bool>` with `dynamic_bitset<>` by
@pinam45 (https://github.com/pinam45/dynamic_bitset) and with
`libpopcnt` for high-performance bit counting by @kimwalisch
(https://github.com/kimwalisch/libpopcnt).

* [x] In support of performance, incremental rendering, and Terminal
  "not speed enough" as well as my sanity relative to
  `std::vector<bool>`
* [x] Tests updated and passed.
* [x] `LICENSE`, `NOTICE`, and provenance files updated.
* [x] I'm a core contributor. I discussed it with @DHowett-MSFT and
  cleared the licensing checks before pulling this in.

## Details `std::vector<bool>` provided by the Microsoft VC Runtime is
incapable of a great many things. Many of the methods you come to expect
off of `std::vector<T>` that are dutifully presented through the `bool`
variant will spontaneously fail at some future date because it decides
you allocated, resized, or manipulated the `vector<bool>` specialization
in an unsupported manner. Half of the methods will straight up not work
for filling/resizing in bulk. And you will tear your hair out as it will
somehow magically forget the assignment of half the bits you gave it
part way through an iteration then assert out and die.

As such, to preserve my sanity, I searched for an alternative. I came
across the self-contained header-only library `dynamic_bitset` by
@pinam45 which appears to do as much of `boost::dynamic_bitset` as I
wanted, but without including 400kg of boost libraries. It also has a
nifty optional dependency on `libpopcnt` by @kimwalisch that will use
processor-specific extensions for rapidly counting bits. @DHowett-MSFT
and I briefly discussed how nice `popcnt` would have been on
`std::vector<bool>` last week... and now we can have it. (To be fair, I
don't believe I'm using it yet... but we'll be able to easily dial in
`til::bitmap` soon and not worry about a performance hit if we do have
to walk bits and count them thanks to `libpopcnt`.)

This PR specifically focuses on swapping the dependencies out and
ingesting the new libraries. We'll further tune `til::bitmap` in future
pulls as necessary.

## Validation
* [x] Ran the automated tests for bitmap.
* [x] Ran the terminal manually and it looks fine still.
2020-03-25 02:41:10 +00:00
Michael Niksa 4d1c7cf3eb Introduce chromium safe math (#4144)
## Summary of the Pull Request

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [x] Closes #4013 
* [x] I work here.
* [x] Existing tests should be OK. Real changes, just adding a lib to use.
* [x] Couldn't find any existing docs about intsafe.
* [x] Am core contributor.

## Detailed Description of the Pull Request / Additional comments
* [x] Can we remove min/max completely or rename it in the two projects where it had to be reintroduced? This is now moved into #4152 
* [x] How many usages of the old safe math are there? **79**
* [x] If not a ton, can we migrate them here or in a follow on PR? This is now moved into #4153

Files with old safe math:
- TerminalControl: TSFInputControl.cpp
- TerminalCore: TerminalDispatch.cpp
- TerminalCore: TerminalSelection.cpp
- Host: directio.cpp
- RendererGdi: invalidate.cpp
- RendererGdi: math.cpp
- RendererGdi: paint.cpp
- RendererVt: paint.cpp
- TerminalAdapter: adaptDispatch.cpp
- Types: viewport.cpp
- Types: WindowUiaProviderBase.cpp

## Validation Steps Performed
2020-01-16 18:51:06 +00:00
Michael Niksa d711d731d7
Apply audit mode to TerminalConnection/Core/Settings and WinCon… (#4016)
## Summary of the Pull Request
- Enables auditing of some Terminal libraries (Connection, Core, Settings)
- Also audit WinConPTY.LIB since Connection depends on it

## PR Checklist
* [x] Rolls audit out to more things
* [x] I work here
* [x] Tests should still pass
* [x] Am core contributor

## Detailed Description of the Pull Request / Additional comments
This is turning on the auditing of these projects (as enabled by the heavier lifting in the other refactor) and then cleaning up the remaining warnings.

## Validation Steps Performed
- [x] Built it
- [x] Ran the tests
2020-01-03 10:44:27 -08:00
Michael Niksa 9cae3c439e Enable Audit Mode for WinRTUtils (#3923)
## Summary of the Pull Request
Turns on Audit for WinRTUtils, fixes audit failures.

## PR Checklist
* [x] I work here
* [x] Still builds
* [x] Am core contributor.

## Validation Steps Performed
Built it.
2019-12-12 13:28:32 +00:00
Dustin L. Howett (MSFT) 357e835f5d
Replace ConhostConnection with ConptyConnection (#3461)
This commit deletes ConhostConnection and replaces it with
ConptyConnection. The ConptyConnection uses CreatePseudoConsole and
depends on winconpty to override the one from kernel32.

* winconpty must be packageable, so I've added GetPackagingOutputs.
   * To validate this, I added conpty.dll to the MSIX regression script.
* I moved the code from conpty-universal that deals with environment
  strings into the types library.

This puts us in a way better place to implement #2563, as we can now
separately detect a failure to launch a pseudoconsole, a failure to
CreateProcess, and an unexpected termination of the launched process.

Fixes #1131.
2019-11-06 15:09:01 -08:00
Dustin L. Howett (MSFT) 9dc922fc37
Unify and clean up the common build properties (#3429)
This commit cleans up and deduplicates all of the common build
preamble/postamble across exe, dll, lib and c++/winrt projects.

The following specific changes have been made:
* All projects now define their ConfigurationType
* All projects now set all their properties *before* including a common
  build file (or any other build files)
* cppwinrt.pre and cppwinrt.post now delegate most of their
  configuration to common.pre and common.post
* (becuase of the above,) all build options are conserved between
  console and c++/winrt components, including specific warnings and
  preprocessor definitions.
* More properties that are configurable per-project are now
  conditioned so the common props don't override them.
* The exe, dll, exe.or.dll, and lib postincludes have been merged into
  pre or post and switched based on condition as required
* Shared items (-shared, -common) are now explicitly vcxitems instead of
  vcxproj files.
* The link line is now manipulated after Microsoft.Cpp sets it, so the
  libraries we specify "win". All console things link first against
  onecore_apiset.lib.
* Fix all compilation errors caused by build unification
* Move CascadiaPackage's resources into a separate item file

Fixes #922.
2019-11-05 14:29:11 -08:00
Michael Niksa 29522c472e
Set utf-8 for the entire project (#1929)
* Set utf-8 for the entire project.
2019-07-11 13:13:10 -07:00
Michael Niksa 5dd1f8d38a
move version to vs2019, the 1903 sdk, and the 14.2 build tools. (#1012)
* move version to vs2019, the 1903 sdk, and the 14.2 build tools.
2019-06-26 14:13:32 -07:00
adiviness cc30475955
add audit mode to ci (#948)
* add audit mode to ci
2019-05-24 14:48:10 -07:00
Dustin Howett d4d59fa339 Initial release of the Windows Terminal source code
This commit introduces all of the Windows Terminal and Console Host source,
under the MIT license.
2019-05-02 15:29:04 -07:00