Skip to content

Commit

Permalink
Merge pull request #1 from chcg/appveyor_x64
Browse files Browse the repository at this point in the history
appveyor + x64

Thank you. Though the approach for the x64 build in this case is to be changed very soon. 

I have just finished yesterday the CS-Script.Npp x64 migration. Only a single outstanding item left (I may need to contact @kbilsted for that).

It was quite interesting dev effort. @kbilsted has done fantastic job of capturing native Npp interface. In many cases his interface was better than that one that I prepared for CSScriptNpp and CSScriptIntellisense. Thus I have changed the codebase to use his API.

Though there were a few critical defects that made the current Kbg.NppPluginNET solution actually unsuitable for hosting any comprehensive plugins. For example calling `GetOpenedFiles` crashes the Npp 100% reliably. I will be preparing the pull request with my fixes so @kbilsted can benefit from this effort as well.

Another very beneficial outcome of this exercise is that I have extended Kbg.NppPluginNET original solution (VS project template) and now building the plugin can be done without exporting the plugin assembly. This makes it possible to have a single-assembly AnyCPU plugin implementation possible. And the x86 vs x64 plugin hosting is the result of a simple packaging technique:

Kbg.NppPluginNET solution is just two files: 
- NppPlugin.Host.dll (compiuled for x86) 
- NppPlugin.Host.dll (compiuled for x64) 

Npp plugin solution:
- 'MyPlugin' VS project  (compiled for AnyCPU and referencing any of two NppPlugin.Host.dll)
- _Any other dependencies_ 

Npp plugin packaging/deployment:
``` 
<x86 ProgramFiles on x64 Windows>
─ Program Files (x86)
  └─ Notepad++
     ├─ plugins
         ├─ MyPlugin
         |  └─ MyPlugin.dll <AnyCPU assembly>
         └─ MyPlugin.x86.dll <renamed x86 version of NppPlugin.Host.dll>

************************

<x64 ProgramFiles on x64 Windows>
─ Program Files
  └─ Notepad++
     ├─ plugins
         ├─ MyPlugin
         |  └─ MyPlugin.dll <AnyCPU assembly>
         └─ MyPlugin.x64.dll <renamed x64 version of NppPlugin.Host.dll>

```                   

I will also be contributing NppPlugin.Host to the kbilsted/NotepadPlusPlusPluginPack.Net
  • Loading branch information
oleg-shilo committed Jan 8, 2018
2 parents e9049ce + 5e527ad commit 209cc00
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 64 deletions.
75 changes: 75 additions & 0 deletions appveyor.yml
@@ -0,0 +1,75 @@
version: 1.0.4.{build}
image: Visual Studio 2017


environment:
matrix:
- PlatformToolset: VS15
- PlatformToolset: VS17

platform:
- x64
- Any CPU

configuration:
- Release
- Debug

install:
- if "%platform%"=="x64" set archi=amd64
- if "%platform%"=="x64" set platform_input=x64

- if "%platform%"=="Any CPU" set archi=x86
- if "%platform%"=="Any CPU" set platform_input=Any CPU

- if "%PlatformToolset%"=="VS15" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %archi%
- if "%PlatformToolset%"=="VS17" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" %archi%


build_script:
- cd "%APPVEYOR_BUILD_FOLDER%"\src
- msbuild NppScripts.sln /m /p:configuration="%configuration%" /p:platform="%platform_input%" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"

after_build:
- cd "%APPVEYOR_BUILD_FOLDER%"\src\NppScripts
- ps: >-
if ($env:PLATFORM_INPUT -eq "x64" -and $env:CONFIGURATION -eq "Release") {
Push-AppveyorArtifact "bin\x64\$env:CONFIGURATION\NppScripts.dll" -FileName NppScripts.dll
}
if ($env:PLATFORM_INPUT -eq "Any CPU" -and $env:CONFIGURATION -eq "Release") {
Push-AppveyorArtifact "bin\$env:CONFIGURATION\NppScripts.dll" -FileName NppScripts.dll
}
if ($($env:APPVEYOR_REPO_TAG) -eq "true" -and $env:CONFIGURATION -eq "Release" -and $env:PLATFORMTOOLSET -eq "VS17") {
if($env:PLATFORM_INPUT -eq "x64"){
$ZipFileName = "NppScripts_$($env:APPVEYOR_REPO_TAG_NAME)_x64.zip"
Remove-Item bin\x64\$env:CONFIGURATION\*.exp
Remove-Item bin\x64\$env:CONFIGURATION\*.lib
7z a $ZipFileName bin\x64\$env:CONFIGURATION\*
}
if($env:PLATFORM_INPUT -eq "Any CPU"){
$ZipFileName = "NppScripts_$($env:APPVEYOR_REPO_TAG_NAME)_x86.zip"
Remove-Item bin\$env:CONFIGURATION\*.exp
Remove-Item bin\$env:CONFIGURATION\*.lib
7z a $ZipFileName bin\$env:CONFIGURATION\*
}
}
artifacts:
- path: NppScripts_*.zip
name: releases

deploy:
provider: GitHub
auth_token:
secure: !!TODO, see https://www.appveyor.com/docs/deployment/github/#provider-settings!!
artifact: releases
draft: false
prerelease: false
force_update: true
on:
appveyor_repo_tag: true
PlatformToolset: VS17
configuration: Release
2 changes: 1 addition & 1 deletion src/HtmlView/HtmlView.csproj
Expand Up @@ -83,7 +83,7 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "C:\Users\osh\Documents\NppScripts\$(TargetFileName)"</PostBuildEvent>
<PostBuildEvent>IF EXIST "$(userprofile)\Documents\NppScripts\" copy "$(TargetPath)" "$(userprofile)\Documents\NppScripts\$(TargetFileName)"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
19 changes: 17 additions & 2 deletions src/NppScripts.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NppScripts", "NppScripts\NppScripts.csproj", "{23B08B10-8297-4A90-9B6D-43DAC7416004}"
EndProject
Expand All @@ -18,23 +18,38 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{23B08B10-8297-4A90-9B6D-43DAC7416004}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23B08B10-8297-4A90-9B6D-43DAC7416004}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23B08B10-8297-4A90-9B6D-43DAC7416004}.Debug|x64.ActiveCfg = Debug|x64
{23B08B10-8297-4A90-9B6D-43DAC7416004}.Debug|x64.Build.0 = Debug|x64
{23B08B10-8297-4A90-9B6D-43DAC7416004}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23B08B10-8297-4A90-9B6D-43DAC7416004}.Release|Any CPU.Build.0 = Release|Any CPU
{23B08B10-8297-4A90-9B6D-43DAC7416004}.Release|x64.ActiveCfg = Release|x64
{23B08B10-8297-4A90-9B6D-43DAC7416004}.Release|x64.Build.0 = Release|x64
{D6DBA062-0EB7-438F-B776-082F81A46E4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D6DBA062-0EB7-438F-B776-082F81A46E4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6DBA062-0EB7-438F-B776-082F81A46E4D}.Debug|x64.ActiveCfg = Debug|Any CPU
{D6DBA062-0EB7-438F-B776-082F81A46E4D}.Debug|x64.Build.0 = Debug|Any CPU
{D6DBA062-0EB7-438F-B776-082F81A46E4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6DBA062-0EB7-438F-B776-082F81A46E4D}.Release|Any CPU.Build.0 = Release|Any CPU
{D6DBA062-0EB7-438F-B776-082F81A46E4D}.Release|x64.ActiveCfg = Release|Any CPU
{D6DBA062-0EB7-438F-B776-082F81A46E4D}.Release|x64.Build.0 = Release|Any CPU
{C4038073-8797-4E92-86AB-B5B9435A224F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C4038073-8797-4E92-86AB-B5B9435A224F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4038073-8797-4E92-86AB-B5B9435A224F}.Debug|x64.ActiveCfg = Debug|Any CPU
{C4038073-8797-4E92-86AB-B5B9435A224F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4038073-8797-4E92-86AB-B5B9435A224F}.Release|Any CPU.Build.0 = Release|Any CPU
{C4038073-8797-4E92-86AB-B5B9435A224F}.Release|x64.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5FFEE081-093B-4E54-BA72-EA9F51914B03}
EndGlobalSection
EndGlobal
18 changes: 0 additions & 18 deletions src/NppScripts/Interop/DllExport/CheckILDasmPath.cs

This file was deleted.

Binary file not shown.
21 changes: 8 additions & 13 deletions src/NppScripts/Interop/DllExport/DllExportAttribute.cs
@@ -1,4 +1,5 @@
using System;
// NPP plugin platform for .Net v0.93.96 by Kasper B. Graversen etc.
using System;
using System.Runtime.InteropServices;

namespace NppPlugin.DllExport
Expand All @@ -9,26 +10,20 @@ partial class DllExportAttribute : Attribute
public DllExportAttribute()
{
}

public DllExportAttribute(string exportName)
: this(exportName, CallingConvention.StdCall)
{
}

public DllExportAttribute(string exportName, CallingConvention callingConvention)
{
ExportName = exportName;
CallingConvention = callingConvention;
}
CallingConvention _callingConvention;
public CallingConvention CallingConvention
{
get { return _callingConvention; }
set { _callingConvention = value; }
}
string _exportName;
public string ExportName
{
get { return _exportName; }
set { _exportName = value; }
}

public CallingConvention CallingConvention { get; set; }

public string ExportName { get; set; }
}
}
Binary file modified src/NppScripts/Interop/DllExport/Mono.Cecil.dll
Binary file not shown.
Binary file not shown.
Binary file modified src/NppScripts/Interop/DllExport/NppPlugin.DllExport.dll
Binary file not shown.
15 changes: 5 additions & 10 deletions src/NppScripts/Interop/DllExport/NppPlugin.DllExport.targets
@@ -1,10 +1,6 @@
<Project
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="NppPlugin.DllExport.MSBuild.DllExportTask"
AssemblyFile="NppPlugin.DllExport.MSBuild.dll"/>
<Target Name="AfterBuild"
DependsOnTargets="GetFrameworkPaths"
>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="NppPlugin.DllExport.MSBuild.DllExportTask" AssemblyFile="NppPlugin.DllExport.MSBuild.dll"/>
<Target Name="AfterBuild" DependsOnTargets="GetFrameworkPaths">
<DllExportTask Platform="$(Platform)"
PlatformTarget="$(PlatformTarget)"
CpuType="$(CpuType)"
Expand All @@ -17,8 +13,7 @@
ProjectDirectory="$(MSBuildProjectDirectory)"
InputFileName="$(TargetPath)"
FrameworkPath="$(TargetedFrameworkDir);$(TargetFrameworkDirectory)"
LibToolPath="$(DevEnvDir)\..\..\VC\bin"
LibToolDllPath="$(DevEnvDir)"
SdkPath="$(FrameworkSDKDir)"/>
SdkPath="$(SDK40ToolsPath)"/>
</Target>
</Project>
</Project>
34 changes: 17 additions & 17 deletions src/NppScripts/Interop/NppPluginNETHelper.cs
Expand Up @@ -83,17 +83,17 @@ public void Add(FuncItem funcItem)
RtlMoveMemory(newPointer, _nativePointer, oldSize);
Marshal.FreeHGlobal(_nativePointer);
}
IntPtr ptrPosNewItem = (IntPtr)((int)newPointer + oldSize);
IntPtr ptrPosNewItem = (IntPtr)(newPointer.ToInt64() + oldSize);
byte[] aB = Encoding.Unicode.GetBytes(funcItem._itemName + "\0");
Marshal.Copy(aB, 0, ptrPosNewItem, aB.Length);
ptrPosNewItem = (IntPtr)((int)ptrPosNewItem + 128);
ptrPosNewItem = (IntPtr)(ptrPosNewItem.ToInt64() + 128);
IntPtr p = (funcItem._pFunc != null) ? Marshal.GetFunctionPointerForDelegate(funcItem._pFunc) : IntPtr.Zero;
Marshal.WriteIntPtr(ptrPosNewItem, p);
ptrPosNewItem = (IntPtr)((int)ptrPosNewItem + IntPtr.Size);
ptrPosNewItem = (IntPtr)(ptrPosNewItem.ToInt64() + IntPtr.Size);
Marshal.WriteInt32(ptrPosNewItem, funcItem._cmdID);
ptrPosNewItem = (IntPtr)((int)ptrPosNewItem + 4);
ptrPosNewItem = (IntPtr)(ptrPosNewItem.ToInt64() + 4);
Marshal.WriteInt32(ptrPosNewItem, Convert.ToInt32(funcItem._init2Check));
ptrPosNewItem = (IntPtr)((int)ptrPosNewItem + 4);
ptrPosNewItem = (IntPtr)(ptrPosNewItem.ToInt64() + 4);
if (funcItem._pShKey._key != 0)
{
IntPtr newShortCutKey = Marshal.AllocHGlobal(4);
Expand All @@ -112,15 +112,15 @@ public void RefreshItems()
{
FuncItem updatedItem = new FuncItem();
updatedItem._itemName = _funcItems[i]._itemName;
ptrPosItem = (IntPtr)((int)ptrPosItem + 128);
ptrPosItem = (IntPtr)(ptrPosItem.ToInt64() + 128);
updatedItem._pFunc = _funcItems[i]._pFunc;
ptrPosItem = (IntPtr)((int)ptrPosItem + IntPtr.Size);
ptrPosItem = (IntPtr)(ptrPosItem.ToInt64() + IntPtr.Size);
updatedItem._cmdID = Marshal.ReadInt32(ptrPosItem);
ptrPosItem = (IntPtr)((int)ptrPosItem + 4);
ptrPosItem = (IntPtr)(ptrPosItem.ToInt64() + 4);
updatedItem._init2Check = _funcItems[i]._init2Check;
ptrPosItem = (IntPtr)((int)ptrPosItem + 4);
ptrPosItem = (IntPtr)(ptrPosItem.ToInt64() + 4);
updatedItem._pShKey = _funcItems[i]._pShKey;
ptrPosItem = (IntPtr)((int)ptrPosItem + IntPtr.Size);
ptrPosItem = (IntPtr)(ptrPosItem.ToInt64() + IntPtr.Size);

_funcItems[i] = updatedItem;
}
Expand Down Expand Up @@ -1119,7 +1119,7 @@ public struct Sci_NotifyHeader
* hwndFrom is really an environment specific window handle or pointer
* but most clients of Scintilla.h do not have this type visible. */
public IntPtr hwndFrom;
public uint idFrom;
public IntPtr idFrom;
public uint code;
}

Expand All @@ -1135,8 +1135,8 @@ public struct SCNotification
public int length; /* SCN_MODIFIED */
public int linesAdded; /* SCN_MODIFIED */
public int message; /* SCN_MACRORECORD */
public uint wParam; /* SCN_MACRORECORD */
public int lParam; /* SCN_MACRORECORD */
public IntPtr wParam; /* SCN_MACRORECORD */
public IntPtr lParam; /* SCN_MACRORECORD */
public int line; /* SCN_MODIFIED */
public int foldLevelNow; /* SCN_MODIFIED */
public int foldLevelPrev; /* SCN_MODIFIED */
Expand Down Expand Up @@ -2251,10 +2251,10 @@ public ClikeStringArray(int num, int stringCapacity)
for (int i = 0; i < num; i++)
{
IntPtr item = Marshal.AllocHGlobal(stringCapacity);
Marshal.WriteIntPtr((IntPtr)((int)_nativeArray + (i * IntPtr.Size)), item);
Marshal.WriteIntPtr((IntPtr)(_nativeArray + (i * IntPtr.Size)), item);
_nativeItems.Add(item);
}
Marshal.WriteIntPtr((IntPtr)((int)_nativeArray + (num * IntPtr.Size)), IntPtr.Zero);
Marshal.WriteIntPtr((IntPtr)(_nativeArray + (num * IntPtr.Size)), IntPtr.Zero);
}

public ClikeStringArray(List<string> lstStrings)
Expand All @@ -2264,10 +2264,10 @@ public ClikeStringArray(List<string> lstStrings)
for (int i = 0; i < lstStrings.Count; i++)
{
IntPtr item = Marshal.StringToHGlobalUni(lstStrings[i]);
Marshal.WriteIntPtr((IntPtr)((int)_nativeArray + (i * IntPtr.Size)), item);
Marshal.WriteIntPtr((IntPtr)(_nativeArray + (i * IntPtr.Size)), item);
_nativeItems.Add(item);
}
Marshal.WriteIntPtr((IntPtr)((int)_nativeArray + (lstStrings.Count * IntPtr.Size)), IntPtr.Zero);
Marshal.WriteIntPtr((IntPtr)(_nativeArray + (lstStrings.Count * IntPtr.Size)), IntPtr.Zero);
}

public IntPtr NativePointer { get { return _nativeArray; } }
Expand Down
23 changes: 20 additions & 3 deletions src/NppScripts/NppScripts.csproj
Expand Up @@ -47,6 +47,24 @@
<Prefer32Bit>false</Prefer32Bit>
<DocumentationFile>bin\Release\NppScripts.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\NppScripts.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DocumentationFile>bin\Release\NppScripts.xml</DocumentationFile>
<Optimize>true</Optimize>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="Interop\DllExport\NppPlugin.DllExport.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down Expand Up @@ -87,7 +105,6 @@
<Compile Include="ScriptNameInput.Designer.cs">
<DependentUpon>ScriptNameInput.cs</DependentUpon>
</Compile>
<None Include="Interop\DllExport\CheckILDasmPath.cs" />
<Compile Include="Interop\DllExport\DllExportAttribute.cs" />
<Compile Include="Interop\NppPluginNETBase.cs" />
<Compile Include="Interop\NppPluginNETHelper.cs" />
Expand Down Expand Up @@ -141,7 +158,6 @@
<None Include="Interop\DllExport\NppPlugin.DllExport.dll" />
<None Include="Interop\DllExport\NppPlugin.DllExport.MSBuild.dll" />
<None Include="Interop\DllExport\README.txt" />
<None Include="Interop\DllExport\CheckILDasmPath.exe" />
</ItemGroup>
<ItemGroup>
<None Include="Interop\DllExport\NppPlugin.DllExport.targets" />
Expand Down Expand Up @@ -208,6 +224,7 @@
</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PreBuildEvent>"$(ProjectDir)Interop\DllExport\CheckILDasmPath.exe"</PreBuildEvent>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
</Project>

1 comment on commit 209cc00

@kbilsted
Copy link

Choose a reason for hiding this comment

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

Many thanks for the kind words. I'm very interested in getting support for x64 and generally improving the plugin platform.

Please sign in to comment.