This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Command-Line Compiler #681
Merged
ScottCarda-MS
merged 20 commits into
feature/azure-quantum-simulator
from
sccarda/CommandLineCompiler
Jun 1, 2021
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b960396
Added command line project
ScottCarda-MS daf3478
Updates to the project file
ScottCarda-MS f0da336
Updated option descriptions, changed includeLibrary to includeLibraries.
ScottCarda-MS 0f96f95
Package reference instead of project reference
ScottCarda-MS 8e6cf60
Changed name and updated version
ScottCarda-MS 8f4b596
changes to project file
ScottCarda-MS 42128a7
made includeDirectories accept multiple arguments
ScottCarda-MS eec547b
minor changes
ScottCarda-MS 126c873
Merge branch 'feature/azure-quantum-simulator' into sccarda/CommandLi…
ScottCarda-MS cf0db65
Fixed help for include-directories
ScottCarda-MS 66f4df3
updated version, added null checks for logger
ScottCarda-MS 5c1158a
remove package reference to runtime
ScottCarda-MS 74ffcca
merged in from feature
ScottCarda-MS c35834d
Added PackAsTool
ScottCarda-MS 2dda015
Allow for multiple library and include paths
ScottCarda-MS b30a174
Make headers and libraries arguments optional
ScottCarda-MS 589d268
fixed tests
ScottCarda-MS 0f37043
fixed API call in controller
ScottCarda-MS 18ca27e
removed unnecessary checks
ScottCarda-MS 9d7fbb6
make output folder flat
ScottCarda-MS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.CommandLine; | ||
| using System.CommandLine.Builder; | ||
| using System.CommandLine.Help; | ||
| using System.CommandLine.Invocation; | ||
| using System.CommandLine.Parsing; | ||
| using System.IO; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Quantum.Qir.Tools; | ||
|
|
||
| namespace Microsoft.Quantum.CommandLineCompiler | ||
| { | ||
| class Program | ||
| { | ||
| private static async Task<int> Main(string[] args) | ||
| { | ||
| var buildCommand = CreateBuildCommand(); | ||
|
|
||
| var root = new RootCommand() { buildCommand }; | ||
| SetSubCommandAsDefault(root, buildCommand); | ||
| root.Description = "Command-line tool for processing QIR DLL files."; | ||
| root.TreatUnmatchedTokensAsErrors = true; | ||
|
|
||
| Console.OutputEncoding = Encoding.UTF8; | ||
| return await new CommandLineBuilder(root) | ||
| .UseDefaults() | ||
| .UseHelpBuilder(context => new QsHelpBuilder(context.Console)) | ||
| .Build() | ||
| .InvokeAsync(args); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates the Build command for the command line compiler, which is used to | ||
| /// compile the executables from a given QIR DLL. | ||
| /// </summary> | ||
| /// <returns>The Build command.</returns> | ||
| private static Command CreateBuildCommand() | ||
| { | ||
| var buildCommand = new Command("build", "(default) Build the executables from a QIR DLL.") | ||
| { | ||
| Handler = CommandHandler.Create((BuildOptions settings) => | ||
| { | ||
| return QirTools.BuildFromQSharpDll(settings.QSharpDll, settings.LibraryDirectories, settings.IncludeDirectories, settings.ExecutablesDirectory); | ||
| }) | ||
| }; | ||
| buildCommand.TreatUnmatchedTokensAsErrors = true; | ||
|
|
||
| buildCommand.AddOption(new Option<FileInfo>( | ||
| aliases: new string[] { "--qsharp-dll", "--dll" }, | ||
| description: "The path to the .NET DLL file generated by the Q# compiler.") | ||
| { | ||
| Required = true | ||
| }); | ||
|
|
||
| buildCommand.AddOption(new Option<DirectoryInfo[]>( | ||
| aliases: new string[] { "--library-directories", "--lib" }, | ||
| description: "One or more paths to the directories containing the libraries to be linked.") | ||
| { | ||
| Required = false, | ||
| Argument = new Argument<DirectoryInfo[]>(() => new DirectoryInfo[] { }) | ||
| { | ||
| Arity = ArgumentArity.OneOrMore | ||
| } | ||
| }); | ||
|
|
||
| buildCommand.AddOption(new Option<DirectoryInfo[]>( | ||
| aliases: new string[] { "--include-directories", "--include" }, | ||
| description: "One or more paths to the directories containing the headers required for compilation.") | ||
| { | ||
| Required = false, | ||
| Argument = new Argument<DirectoryInfo[]>(() => new DirectoryInfo[] { }) | ||
| { | ||
| Arity = ArgumentArity.OneOrMore | ||
| } | ||
| }); | ||
|
|
||
| buildCommand.AddOption(new Option<DirectoryInfo>( | ||
| aliases: new string[] { "--executables-directory", "--exe" }, | ||
| description: "The path to the output directory where the created executables will be placed.") | ||
| { | ||
| Required = true | ||
| }); | ||
|
|
||
| return buildCommand; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Copies the handle and options from the given sub command to the given command. | ||
| /// </summary> | ||
| /// <param name="root">The command whose handle and options will be set.</param> | ||
| /// <param name="subCommand">The sub command that will be copied from.</param> | ||
| private static void SetSubCommandAsDefault(Command root, Command subCommand) | ||
| { | ||
| root.Handler = subCommand.Handler; | ||
| foreach (var option in subCommand.Options) | ||
| { | ||
| root.AddOption(option); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A modification of the command-line <see cref="HelpBuilder"/> class. | ||
| /// </summary> | ||
| private sealed class QsHelpBuilder : HelpBuilder | ||
| { | ||
| /// <summary> | ||
| /// Creates a new help builder using the given console. | ||
| /// </summary> | ||
| /// <param name="console">The console to use.</param> | ||
| internal QsHelpBuilder(IConsole console) : base(console) | ||
| { | ||
| } | ||
|
|
||
| protected override string ArgumentDescriptor(IArgument argument) | ||
| { | ||
| // Hide long argument descriptors. | ||
| var descriptor = base.ArgumentDescriptor(argument); | ||
| return descriptor.Length > 30 ? argument.Name : descriptor; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A class for encapsulating the different options for the build command. | ||
| /// </summary> | ||
| public sealed class BuildOptions | ||
| { | ||
| /// <summary> | ||
| /// The path to the .NET DLL file generated by the Q# compiler. | ||
| /// </summary> | ||
| public FileInfo QSharpDll { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// One or more paths to the directories containing the libraries to be linked. | ||
| /// </summary> | ||
| public DirectoryInfo[] LibraryDirectories { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// One or more paths to the directories containing the headers required for compilation. | ||
| /// </summary> | ||
| public DirectoryInfo[] IncludeDirectories { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The path to the output directory where the created executables will be placed. | ||
| /// </summary> | ||
| public DirectoryInfo ExecutablesDirectory { get; set; } | ||
| } | ||
| } | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
src/Qir/Execution/QirCommandLineTool/QirCommandLineTool.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>netcoreapp3.1</TargetFramework> | ||
| <PackAsTool>true</PackAsTool> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20213.1" /> | ||
| <ProjectReference Include="..\..\..\Simulation\Simulators\Microsoft.Quantum.Simulators.csproj" /> | ||
| <ProjectReference Include="..\Tools\Microsoft.Quantum.Qir.Tools.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.