Skip to content
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

CMake: Set up Visual D when using the Visual Studio generator #3494

Merged
merged 3 commits into from
Jul 9, 2020

Conversation

kinke
Copy link
Member

@kinke kinke commented Jul 5, 2020

For a smooth out-of-the-box experience after something like:

cmake C:\LDC\ldc
      -G "Visual Studio 16 2019"
      -A x64
      -DLLVM_ROOT_DIR=C:\LDC\LLVM-x64
      -DD_COMPILER=C:\LDC\ldc2-1.22.0-windows-multilib\bin\ldmd2
start ldc.sln

For a smooth out-of-the-box experience after something like:

cmake ..\ldc
      -G "Visual Studio 16 2019"
      -A x64
      -DLLVM_ROOT_DIR=C:\LDC\LLVM-x64
      -DD_COMPILER=C:\LDC\ldc2-1.22.0-windows-multilib\bin\ldmd2
@kinke
Copy link
Member Author

kinke commented Jul 5, 2020

FYI @rainers. Apparently it's not a perfect solution (https://cmake.org/cmake/help/latest/prop_tgt/VS_USER_PROPS.html), but it seems to suffice in my case (edit & debug in VS, build in the shell with ninja) - tested with Visual D v1.0. There are still no Visual D properties for the project, I guess that would require adding some dummy <DCompile /> item (CMake adds all .d files as <None /> items).

@kinke
Copy link
Member Author

kinke commented Jul 5, 2020

Btw Rainer, the back button on my mouse doesn't navigate backward after jumping with F12 (over the editor; nothing happens). The navigation buttons in the toolbar work as expected, but the extra mouse buttons don't (but do for C++ files).

@rainers
Copy link
Contributor

rainers commented Jul 6, 2020

There are still no Visual D properties for the project, I guess that would require adding some dummy <DCompile /> item (CMake adds all .d files as <None /> items).

Indeed, the options only appear if there is at least one file included for rule <DCompile>. Maybe you can generate this instead of the custom rules with a combination of VS_TOOL_OVERRIDE and VS_SOURCE_SETTINGS_<tool>.

@rainers
Copy link
Contributor

rainers commented Jul 6, 2020

Btw Rainer, the back button on my mouse doesn't navigate backward after jumping with F12

IIRC that functionality is not covered by any command that can be reimplemented, but has to be done by explicit mouse handling hooking into the text editor. Something similar has been added recently to Visual D, so I might be able to revisit that.

@kinke
Copy link
Member Author

kinke commented Jul 6, 2020

Thx for the VS_TOOL_OVERRIDE hint, that works indeed to make them all <DCompile>. I got rid of the custom command (hey, now there's an actual ldc2 project in the VS solution...). Building ldc2.exe in VS this way, i.e., letting Visual D compile the .d files as part of the LDCShared lib (usually, just the C++ parts), seems to almost work, the linker is just complaining about conflicting MSCRT versions. Plus there's something like 17k warnings (LLVM headers), and it takes ages due to serially building the .cpp modules out of the box - so since I prefer ninja anyway, this is good enough for me.

@kinke kinke force-pushed the visuald branch 3 times, most recently from 2b14594 to ef63863 Compare July 7, 2020 00:10
@rainers
Copy link
Contributor

rainers commented Jul 7, 2020

letting Visual D compile the .d files as part of the LDCShared lib (usually, just the C++ parts), seems to almost work

Nice.

, the linker is just complaining about conflicting MSCRT versions.

Adding this to the DCompile section in your prop file should work:

      <CRuntimeLibrary>None</CRuntimeLibrary>

and it takes ages due to serially building the .cpp modules out of the box

I think cmake doesn't enable parallel compilation by default, adding this to your prop file might help:

    <ClCompile>
      <MultiProcessorCompilation>true</MultiProcessorCompilation>
    </ClCompile>

@kinke
Copy link
Member Author

kinke commented Jul 7, 2020

Thx, MultiProcessorCompilation works fine (edit: for the C++ parts; the D object file is still built separately as first thing for the LDCShared lib, the C++ jobs are processed in parallel after that). Building the ldc2 project, i.e., ldc2.exe, now (rather surprisingly) works out of the box with both Release and RelWithDebInfo configs - using our prebuilt LLVM (which was built with clang, which probably accounts for the ~8k C++ warnings) [and a LDC 1.22 host compiler; I haven't tried DMD].

@kinke
Copy link
Member Author

kinke commented Jul 7, 2020

Btw, I can't test DMD via the IDE, the custom .props file seems to expose a small issue:

image

When I try to select DMD explicitly and apply, the compiler is still LDC.

@rainers
Copy link
Contributor

rainers commented Jul 7, 2020

When I try to select DMD explicitly and apply, the compiler is still LDC.

I guess that happens because you switched the default compiler in the props file. The position of the import might also be a factor,

@kinke
Copy link
Member Author

kinke commented Jul 7, 2020

I've just transplanted that property from .vcxproj to .props, just like the other settings, which can all be overridden from the GUI. It's not even overridable in the .vcxproj (shows up as bold, but used compiler and compiler shown in the lhs properties tree remains LDC). - Anyway, no big deal at all.

@kinke kinke merged commit 1e22f4f into ldc-developers:master Jul 9, 2020
@kinke kinke deleted the visuald branch July 9, 2020 17:12
@kinke
Copy link
Member Author

kinke commented Aug 8, 2020

Btw Rainer, the back button on my mouse doesn't navigate backward after jumping with F12

IIRC that functionality is not covered by any command that can be reimplemented, but has to be done by explicit mouse handling hooking into the text editor. Something similar has been added recently to Visual D, so I might be able to revisit that.

@rainers: Can you point me to some commit/PR? It's really a minor feature I can hardly live without... :]

@rainers
Copy link
Contributor

rainers commented Aug 9, 2020

I was thinking about one of these mouse handlers:
https://github.com/dlang/visuald/blob/92ec7a24278a2e32583137f250f2ddae4e67c41d/vdextensions/gotodef.cs#L221
https://github.com/dlang/visuald/blob/92ec7a24278a2e32583137f250f2ddae4e67c41d/vdextensions/quickinfo.cs#L65
but maybe they are actually not so useful to implement the back button.

Maybe this extension is helpful: https://marketplace.visualstudio.com/items?itemName=SamHarwell.MouseNavigation

Edit: just looked at its source: maybe very easy to add to the GotoDefMouseHandler, but none of my mice have these extra buttons to try.

@kinke
Copy link
Member Author

kinke commented Aug 9, 2020

Thx; I've had a go, but failed to build the vdext15 project and gave up. I'd be more than happy to test a build - here's the patch:

--- a/vdextensions/gotodef.cs
+++ b/vdextensions/gotodef.cs
@@ -182,6 +182,7 @@ namespace vdext15
             var buffer = view.TextBuffer;

             IOleCommandTarget shellCommandDispatcher = GetShellCommandDispatcher(view);
+            IVsUIShell vsUIShell = GetVsUIShell();

             if (shellCommandDispatcher == null)
                 return null;
@@ -196,6 +197,7 @@ namespace vdext15

                        return new GoToDefMouseHandler(view,
                                            shellCommandDispatcher,
+                                           vsUIShell,
                                            _aggregatorFactory.GetClassifier(buffer),
                                            _navigatorService.GetTextStructureNavigator(buffer),
                                            CtrlKeyState.GetStateForView(view));
@@ -211,6 +213,14 @@ namespace vdext15
             return _globalServiceProvider.GetService(typeof(SUIHostCommandDispatcher)) as IOleCommandTarget;
         }

+        /// <summary>
+        /// Get the SVsUIShell from the global service provider.
+        /// </summary>
+        private IVsUIShell GetVsUIShell()
+        {
+            return _globalServiceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;
+        }
+
         #endregion
     }

@@ -225,12 +235,14 @@ namespace vdext15
         private IClassifier _aggregator;
         private ITextStructureNavigator _navigator;
         private IOleCommandTarget _commandTarget;
+        private IVsUIShell _vsUIShell;

-        public GoToDefMouseHandler(IWpfTextView view, IOleCommandTarget commandTarget,
+        public GoToDefMouseHandler(IWpfTextView view, IOleCommandTarget commandTarget, IVsUIShell vsUIShell,
             IClassifier aggregator, ITextStructureNavigator navigator, CtrlKeyState state)
         {
             _view = view;
             _commandTarget = commandTarget;
+            _vsUIShell = vsUIShell;
             _state = state;
             _aggregator = aggregator;
             _navigator = navigator;
@@ -315,6 +327,27 @@ namespace vdext15
             _mouseDownAnchorPoint = null;
         }

+        // Support backward/forward navigation via extended mouse buttons.
+        // Derived from https://github.com/tunnelvisionlabs/MouseNavigation/blob/master/Tvl.VisualStudio.MouseNavigation/MouseNavigationProcessor.cs.
+        public override void PostprocessMouseUp(MouseButtonEventArgs e)
+        {
+            if (_vsUIShell == null)
+                return;
+
+            uint cmdId;
+            if (e.ChangedButton == MouseButton.XButton1)
+                cmdId = (uint)VSConstants.VSStd97CmdID.ShellNavBackward;
+            else if (e.ChangedButton == MouseButton.XButton2)
+                cmdId = (uint)VSConstants.VSStd97CmdID.ShellNavForward;
+            else
+                return;
+
+            object obj = null;
+            _vsUIShell.PostExecCommand(VSConstants.GUID_VSStandardCommandSet97, cmdId,
+                (uint)OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref obj);
+
+            e.Handled = true;
+        }

         #endregion

@rainers
Copy link
Contributor

rainers commented Aug 12, 2020

Not exactly the same build as a release, but you can try the installer from https://ci.appveyor.com/project/rainers/visuald/builds/34611854/artifacts

@kinke
Copy link
Member Author

kinke commented Aug 13, 2020

Thx! I've fortunately not yet uninstalled VS 2017 (installer wouldn't detect VS 2019), and the back/forward buttons work like a charm.

@rainers
Copy link
Contributor

rainers commented Aug 14, 2020

installer wouldn't detect VS 2019

That's the Appveyor build only, as it runs in a VS2017 environment and cannot build some components for VS2019.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants