Skip to content

Commit

Permalink
Allow passing a -target-framework option to build.sh (mono#1718)
Browse files Browse the repository at this point in the history
Closes mono#1717.
  • Loading branch information
tritao authored Feb 18, 2023
1 parent 5715df5 commit 8cf6e3f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
17 changes: 16 additions & 1 deletion build/Helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ 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");
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 = "net6.0"

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
4 changes: 4 additions & 0 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ The following steps should be called from the VS developer command prompt.
<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:
Expand Down Expand Up @@ -82,6 +84,8 @@ When opening the solution for the first time on a more recent version than Visua
./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: 0 additions & 1 deletion src/CLI/CppSharp.CLI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 8cf6e3f

Please sign in to comment.