Skip to content

Synced our CppSharp fork with main #8

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 28 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8de0248
Incorrect build instructions on Windows (#1701)
aybe Nov 28, 2022
e2141f1
Misc changes (#1710)
tritao Feb 2, 2023
a1a6fd1
Add C++ WebAssembly ABI (#1711)
tritao Feb 3, 2023
7a85667
Add initial Emscripten generator. (#1712)
tritao Feb 3, 2023
c41fabc
Code cleanups and improvements (#1713)
tritao Feb 4, 2023
7304bb5
Publish package to nuget.org when a version tag is created
josetr Feb 5, 2023
30f0f14
Allow passing a `-target-framework` option to `build.sh` (#1718)
tritao Feb 18, 2023
387e188
Remove unused LLVM build flags.
tritao Mar 8, 2023
4962685
Update LLVM workflow to latest Action images.
tritao Mar 8, 2023
51039a7
Update LLVM Windows workflow to latest Action images.
tritao Mar 8, 2023
94ec2ce
Update action steps to latest to fix Node.js deprecation warnings.
tritao Mar 8, 2023
777e02e
Update LLVM build script for Visual Studio 2022.
tritao Mar 8, 2023
cafa6a0
Workaround Directory.Build.props getting picked up when building LLVM.
tritao Mar 8, 2023
4125eda
Added variation of https://github.com/mono/CppSharp/pull/1736
JordanL8 Aug 29, 2023
b4c9ad2
Workaround parsing GNU system headers with GCC 11.0 version. (#1737)
tritao May 30, 2023
5ca6e69
CppSharp.AST.Declaration - fix return QualifiedOriginalName, Qualifie…
stachu99 Jul 4, 2023
0631184
CSharpExpressionPrinter: Wrap expression in parenthesis (#1741)
trungnt2910 Jul 9, 2023
a476e11
Update README.md
tritao Jul 11, 2023
38077e0
CSharpExpressionPrinter: Recurse into operands (#1745)
trungnt2910 Jul 12, 2023
dd17686
CSharp: More default parameter fixes (#1747)
trungnt2910 Jul 14, 2023
f4e1614
Add type parameter to non-type template parameter decls. (#1749)
tritao Jul 14, 2023
78772d1
Update parser example to latest API.
tritao Jul 14, 2023
d25fe6f
Fixed debugging printing when type printing delegate is not initialized.
tritao Jul 14, 2023
a94bb2f
Array marshalling (#1748)
trungnt2910 Jul 14, 2023
13dd389
Add qualified template name to GetCXXRecordDeclFromBaseType. (#1751)
tritao Jul 17, 2023
24cc638
SymbolResolver: Use filename when path cannot be found (#1752)
trungnt2910 Jul 19, 2023
a120b88
CSharpSources: Dereference pointer variables (#1753)
trungnt2910 Jul 21, 2023
6def133
Use TypePrinter.IntPtrType in CSharpSources.cs code from previous com…
tritao Jul 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/llvm-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
fail-fast: false
matrix:
config:
- { os: windows-2019, platform: x86, vs: 2019 }
- { os: windows-2019, platform: x64, vs: 2019 }
- { os: windows-2022, platform: x86, vs: 2022 }
- { os: windows-2022, platform: x64, vs: 2022 }

runs-on: ${{ matrix.config.os }}

Expand All @@ -23,7 +23,7 @@ jobs:

steps:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v3.x
uses: rlespinasse/github-slug-action@v4

- name: Check out
shell: cmd
Expand All @@ -35,7 +35,7 @@ jobs:
- name: Environment
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\%VS_VERSION%\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %PLATFORM%
call "C:\Program Files\Microsoft Visual Studio\%VS_VERSION%\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %PLATFORM%
:: Loop over all environment variables and make them global using set-env.
:: See: https://stackoverflow.com/a/39184941
setlocal
Expand All @@ -60,7 +60,7 @@ jobs:
working-directory: C:\CppSharp

- name: 'Upload Artifact'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: llvm
path: C:\CppSharp\build\llvm\llvm-*-*.*
10 changes: 5 additions & 5 deletions .github/workflows/llvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
fail-fast: false
matrix:
config:
- { os: ubuntu-20.04, platform: x64, cxx: g++-9, cc: gcc-9 }
- { os: ubuntu-20.04, platform: x64, cxx: g++-10, cc: gcc-10 }
- { os: macos-10.15, platform: x64, cxx: clang++, cc: clang }
- { os: ubuntu-22.04, platform: x64, cxx: g++-11, cc: gcc-11 }
- { os: macos-11, platform: x64, cxx: clang++, cc: clang }
- { os: macos-12, platform: x64, cxx: clang++, cc: clang }

runs-on: ${{ matrix.config.os }}

Expand All @@ -22,7 +22,7 @@ jobs:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: lukka/get-cmake@latest

- name: Clone LLVM
Expand All @@ -38,7 +38,7 @@ jobs:
run: build/build.sh package_llvm -platform $PLATFORM

- name: 'Upload Artifact'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: llvm
path: build/llvm/llvm-*-*.*
10 changes: 8 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ jobs:
runs-on: windows-2019
needs: build
if: |
(github.event_name == 'push' && (github.ref == 'refs/heads/main' || contains(github.ref, 'nuget'))) ||
(github.event.pull_request.head.repo.full_name != github.repository && contains(github.event.pull_request.head.ref, 'nuget'))
(github.event_name == 'push' && (github.ref == 'refs/heads/main' || contains(github.ref, 'nuget') || startsWith(github.ref, 'refs/tags/v'))) ||
(github.event.pull_request.head.repo.full_name != github.repository && (contains(github.event.pull_request.head.ref, 'nuget') || startsWith(github.event.pull_request.head.ref, 'refs/tags/v')))

env:
DOTNET_NOLOGO: true
Expand Down Expand Up @@ -111,3 +111,9 @@ jobs:
run: |
cd artifacts
dotnet nuget push "*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/mono/index.json" --skip-duplicate

- name: Publish package to nuget.org
if: startsWith(github.ref, 'refs/tags/v')
run: |
cd artifacts
dotnet nuget push "*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source "https://api.nuget.org/v3/index.json" --skip-duplicate
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "build/modules/premake-qt"]
path = build/modules/premake-qt
url = https://github.com/dcourtois/premake-qt.git
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<GeneratorFileExtension>dll</GeneratorFileExtension>
<DotNetCmd Condition="'$(PlatformTarget)' == 'x86' AND Exists('$(MSBuildProgramFiles32)\dotnet\dotnet.exe')">"$(MSBuildProgramFiles32)\dotnet\dotnet.exe"</DotNetCmd>
<DotNetCmd Condition="'$(PlatformTarget)' == 'x64' AND Exists('$(ProgramW6432)\dotnet\dotnet.exe')">"$(ProgramW6432)\dotnet\dotnet.exe"</DotNetCmd>
<RID Condition="$(IsWindows)">win</RID>
<RID Condition="$(IsWindows)">win</RID>
<RID Condition="$(IsLinux)">linux</RID>
<RID Condition="$(IsMacOSX)">osx</RID>
<RID>$(RID)-$(PlatformTarget)</RID>
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ Please see the following resources for more information:

Feel free to open up issues on Github for any problems you find.

You can also join us at our [#managed-interop](https://gitter.im/managed-interop) Gitter discussion channel.

## Support

For building wrappers and priority support please write to &#99;&#112;&#112;&#115;&#104;&#97;&#114;&#112;&#64;&#112;&#114;&#111;&#116;&#111;&#110;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;.
Expand Down
19 changes: 17 additions & 2 deletions build/Helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ newoption {
description = "Only generate configuration file",
}

newoption {
trigger = "target-framework",
description = ".NET target framework version",
}

rootdir = path.getabsolute("../")
srcdir = path.join(rootdir, "src");
incdir = path.join(rootdir, "include");
examplesdir = path.join(rootdir, "examples");
testsdir = path.join(rootdir, "tests");
testsdir = path.join(rootdir, "tests/dotnet");
builddir = path.join(rootdir, "build")
bindir = path.join(rootdir, "bin")
objsdir = path.join(builddir, "obj");
Expand All @@ -61,7 +66,17 @@ msvc_cpp_defines = { }
default_gcc_version = "9.0.0"
generate_build_config = true
premake.path = premake.path .. ";" .. path.join(builddir, "modules")
targetframework = "netcoreapp3.1"

function string.isempty(s)
return s == nil or s == ''
end

local function target_framework()
local value = _OPTIONS["target-framework"]
return string.isempty(value) and "net6.0" or value
end

targetframework = target_framework()

function string.starts(str, start)
if str == nil then return end
Expand Down
12 changes: 9 additions & 3 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ vs=vs2019
configuration=Release
build_only=false
ci=false
target_framework=
verbosity=minimal
rootdir="$builddir/.."
bindir="$rootdir/bin"
Expand Down Expand Up @@ -46,18 +47,18 @@ build()

generate_config()
{
"$builddir/premake.sh" --file="$builddir/premake5.lua" $vs --os=$os --arch=$platform --configuration=$configuration --config_only
"$builddir/premake.sh" --file="$builddir/premake5.lua" $vs --os=$os --arch=$platform --configuration=$configuration --target-framework=$target_framework --config_only
}

generate()
{
download_llvm

if [ "$os" = "linux" ] || [ "$os" = "macosx" ]; then
"$builddir/premake.sh" --file="$builddir/premake5.lua" gmake2 --os=$os --arch=$platform --configuration=$configuration "$@"
"$builddir/premake.sh" --file="$builddir/premake5.lua" gmake2 --os=$os --arch=$platform --configuration=$configuration --target-framework=$target_framework "$@"
fi

"$builddir/premake.sh" --file="$builddir/premake5.lua" $vs --os=$os --arch=$platform --configuration=$configuration
"$builddir/premake.sh" --file="$builddir/premake5.lua" $vs --os=$os --arch=$platform --configuration=$configuration --target-framework=$target_framework
}

restore()
Expand Down Expand Up @@ -194,6 +195,11 @@ while [[ $# > 0 ]]; do
os=$2
shift
;;
-target-framework)
target_framework=$2
echo $target_framework
shift
;;
-ci)
ci=true
export CI=true
Expand Down
3 changes: 3 additions & 0 deletions build/llvm/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<!-- This empty file is to workaround MSBuild picking up the root Directy.Build.props when building LLVM. -->
</Project>
12 changes: 7 additions & 5 deletions build/llvm/LLVM.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ end

function get_vs_version()
local function map_msvc_to_vs_version(major, minor)
if major == "19" and minor >= "20" then return "vs2019"
if major == "19" and minor >= "30" then return "vs2022"
elseif major == "19" and minor >= "20" then return "vs2019"
elseif major == "19" and minor >= "10" then return "vs2017"
end
end

local function map_msbuild_to_vs_version(major, minor)
if major == "16" then return "vs2019"
if major == "17" then return "vs2022"
elseif major == "16" then return "vs2019"
elseif major == "15" then return "vs2017"
end
end
Expand Down Expand Up @@ -379,8 +381,6 @@ function cmake(gen, conf, builddir, options)
.. ' -DCLANG_TOOL_C_INDEX_TEST_BUILD=false'
.. ' -DCLANG_TOOL_DIAGTOOL_BUILD=false'
.. ' -DCLANG_TOOL_DRIVER_BUILD=false'
.. ' -DCLANG_TOOL_HANDLE_CXX_BUILD=false'
.. ' -DCLANG_TOOL_HANDLE_LLVM_BUILD=false'
.. ' -DCLANG_TOOL_LIBCLANG_BUILD=false'
.. ' -DCLANG_TOOL_SCAN_BUILD_BUILD=false'
.. ' -DCLANG_TOOL_SCAN_BUILD_PY_BUILD=false'
Expand All @@ -399,7 +399,9 @@ end

function get_cmake_generator()
local vsver = get_vs_version()
if vsver == "vs2019" then
if vsver == "vs2022" then
return "Visual Studio 17 2022", (target_architecture() == "x86") and "-A Win32" or nil
elseif vsver == "vs2019" then
return "Visual Studio 16 2019", (target_architecture() == "x86") and "-A Win32" or nil
elseif vsver == "vs2017" then
return "Visual Studio 15 2017" .. (target_architecture() == "x64" and " Win64" or ""), nil
Expand Down
1 change: 0 additions & 1 deletion build/modules/premake-qt
Submodule premake-qt deleted from 0ddc49
2 changes: 1 addition & 1 deletion build/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ workspace "CppSharp"
workspacefiles(path.join(builddir, "premake5.lua"))
workspacefiles(path.join(builddir, "*.sh"))
workspacefiles(path.join(rootdir, ".github/workflows/*.yml"))
workspacefiles(path.join(rootdir, "tests/Test*.props"))
workspacefiles(path.join(testsdir, "Test*.props"))

group "Libraries"
if EnableNativeProjects() then
Expand Down
27 changes: 24 additions & 3 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,46 @@ make sure those are installed on your system.

## Compiling on Windows/Visual Studio

The following steps should be called from the VS developer command prompt.

1. Generate the VS solution

```shell
cd <CppSharp>\build
./build.sh generate -configuration Release -platform x64
<sh> build.sh generate -configuration Release -platform x64
```

> :information_source: You can use the `-target-framework` option to target any valid .NET target framework.

2. Compile the VS projects

You can open `CppSharp.sln` and hit F5 or compile via the command line:

```
./build.sh -configuration Release -platform x64
<sh> build.sh -configuration Release -platform x64
```

Building in *Release* is recommended because else we will use the Clang parser
debug configuration, which will be too slow for practical use beyond debugging.

The solution generated will be for Visual Studio 2019.

If you have a more recent version of Visual Studio, you can either:
- install Visual Studio 2019
- install Visual Studio 2019 build tools, from [Visual Studio Installer](https://visualstudio.microsoft.com/downloads/)
- select the payload *MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.29-16.11)*

Please note that Windows isn't natively able to run sh scripts, to remediate this, you can either:

- use the one from Visual Studio if present
- e.g. `C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\usr\bin\sh.exe`
- use the one from [Git for Windows](https://gitforwindows.org/)
- e.g. `C:\Program Files\Git\bin\sh.exe`

When opening the solution for the first time on a more recent version than Visual Studio 2019, you will be prompted to retarget projects to one of the platform toolset available on your system.

## Compiling on macOS or Linux

The following steps should be called from the VS developer command prompt.

1. Generate the VS solution and makefiles

Expand All @@ -65,6 +84,8 @@ The following steps should be called from the VS developer command prompt.
./build.sh generate -configuration Release -platform x64
```

> :information_source: You can use the `-target-framework` option to target any valid .NET target framework.

2. Compile the csproj files and makefiles

```
Expand Down
1 change: 1 addition & 0 deletions docs/UsersManual.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ There is also experimental support for these JavaScript-related targets:
- N-API (Node.js)
- QuickJS
- TypeScript
- Emscripten

# 3. Native Targets

Expand Down
11 changes: 4 additions & 7 deletions examples/Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public static void Main(string[] args)
ParseSourceFile(file);
}

public static bool ParseSourceFile(string file)
private static bool ParseSourceFile(string file)
{
// Lets setup the options for parsing the file.
var parserOptions = new ParserOptions
{
LanguageVersion = LanguageVersion.CPP11,
LanguageVersion = LanguageVersion.CPP20_GNU,

// Verbose here will make sure the parser outputs some extra debugging
// information regarding include directories, which can be helpful when
Expand All @@ -37,13 +37,10 @@ public static bool ParseSourceFile(string file)
};

// This will setup the necessary system include paths and arguments for parsing.
// It will probe into the registry (on Windows) and filesystem to find the paths
// of the system toolchains and necessary include directories.
parserOptions.Setup();
parserOptions.Setup(Platform.Host);

// We create the Clang parser and parse the source code.
var parser = new ClangParser();
var parserResult = parser.ParseSourceFile(file, parserOptions);
var parserResult = ClangParser.ParseSourceFile(file, parserOptions);

// If there was some kind of error parsing, then lets print some diagnostics.
if (parserResult.Kind != ParserResultKind.Success)
Expand Down
3 changes: 2 additions & 1 deletion src/AST/ASTContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public enum CppAbi
Microsoft,
ARM,
iOS,
iOS64
iOS64,
WebAssembly
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/AST/Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ public Method FindMethodByUSR(string usr)
.FirstOrDefault(m => m.USR == usr);
}

public Variable FindVariable(string name)
{
return Variables.FirstOrDefault(m => m.Name == name);
}

public override T Visit<T>(IDeclVisitor<T> visitor)
{
return visitor.VisitClassDecl(this);
Expand Down
9 changes: 1 addition & 8 deletions src/AST/ClassLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ public struct VTableComponent
public Declaration Declaration;

/// Method declaration (if Kind == FunctionPointer).
public Method Method
{
get
{
Debug.Assert(Kind == VTableComponentKind.FunctionPointer);
return Declaration as Method;
}
}
public Method Method => Declaration as Method;
}

/// <summary>
Expand Down
Loading