Skip to content

Commit

Permalink
Create a single nuget package that supports windows / linux / macos
Browse files Browse the repository at this point in the history
  • Loading branch information
josetr authored and tritao committed Dec 14, 2020
1 parent fa7e76f commit 62e9119
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 555 deletions.
47 changes: 40 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,46 @@ jobs:
shell: bash
run: build/test.sh -platform $PLATFORM

- name: 'Upload Artifact'
uses: actions/upload-artifact@v2
if: github.ref == 'refs/heads/master'
- name: Pack
shell: bash
run: build/build.sh prepack -platform $PLATFORM

- uses: actions/upload-artifact@v2
with:
name: cppsharp-${{ matrix.config.os }}-${{ matrix.config.platform }}-${{ matrix.config.cc }}
name: intermediate
path: |
bin/**/CppSharp*
bin/**/Std-symbols*
bin/**/lib/**
artifacts
include/**/*.h
create_package:
runs-on: windows-2019
needs: build
if: |
(github.event_name == 'push' && (github.ref == 'refs/heads/master' || contains(github.ref, 'nuget'))) ||
(github.event.pull_request.head.repo.full_name != github.repository && contains(github.event.pull_request.head.ref, 'nuget'))
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true

steps:
- uses: actions/checkout@v2

- uses: actions/download-artifact@v2
with:
name: intermediate

- name: Setup
shell: bash
run: build/build.sh generate_config

- name: Create package
shell: bash
run: build/build.sh pack

- name: Upload package
uses: actions/upload-artifact@v2
with:
name: CppSharp.nupkg
path: |
artifacts/*.nupkg
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ src/generator/generator
/build/config.props
/build/premake/premake5*
/build/gen
/artifacts
/deps/llvm
/extra
/include/include
Expand Down
20 changes: 19 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,36 @@
<RootDir>$(MSBuildThisFileDirectory)</RootDir>
<Platforms>x86;x64</Platforms>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/mono/CppSharp</RepositoryUrl>
<RepositoryCommit>$(GITHUB_SHA)</RepositoryCommit>
<Authors>João Matos, Dimitar Dobrev, Jose Torres</Authors>
<Copyright>João Matos, Dimitar Dobrev</Copyright>
<Version>0.10.6</Version>
<IsPackable>false</IsPackable>
<BuildDir>$(RootDir)build\</BuildDir>
<ObjDir>$(BuildDir)obj\</ObjDir>
<GenDir>$(BuildDir)gen\</GenDir>
<SrcDir>$(RootDir)src\</SrcDir>
<GlobalTargetFramework>$(TargetFramework)</GlobalTargetFramework>
<BaseIntermediateOutputPath>$(ObjDir)$(MSBuildProjectName)\</BaseIntermediateOutputPath>
<BaseOutputPath>$(RootDir)bin\</BaseOutputPath>
<OutputPath>$(BaseOutputPath)$(Configuration)_$(PlatformTarget)\</OutputPath>
<ActionDir>$(BuildDir)$(PremakeAction)\</ActionDir>
<NativeProjectsDir>$(ActionDir)projects\</NativeProjectsDir>
<PackageDir>$(RootDir)artifacts\package\</PackageDir>
<TargetDir>$(OutputPath)</TargetDir>
<LangVersion>8.0</LangVersion>
<WarningLevel>4</WarningLevel>
<DotNetCmd>dotnet</DotNetCmd>
<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="$(IsLinux)">linux</RID>
<RID Condition="$(IsMacOSX)">osx</RID>
<RID>$(RID)-$(PlatformTarget)</RID>
</PropertyGroup>

<PropertyGroup Condition="'$(CPPSHARP_RELEASE)' != 'true'">
Expand All @@ -34,4 +47,9 @@
<GeneratorFileExtension>exe</GeneratorFileExtension>
<DotNetCmd></DotNetCmd>
</PropertyGroup>

<Target Name="prepack" DependsOnTargets="Build" Condition="'$(IsPackable)' == 'true'">
<Copy SourceFiles="$(TargetDir)ref\$(TargetFileName)" DestinationFolder="$(PackageDir)ref\$(GlobalTargetFramework)" Condition="'$(ProduceReferenceAssembly)' == 'true' AND '$(RID)' == 'win-x64'" />
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(PackageDir)runtimes\$(RID)\lib\$(GlobalTargetFramework)" />
</Target>
</Project>
5 changes: 5 additions & 0 deletions build/Helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ newoption {
}
}

newoption {
trigger = "config_only",
description = "Only generate configuration file",
}

rootdir = path.getabsolute("../")
srcdir = path.join(rootdir, "src");
incdir = path.join(rootdir, "include");
Expand Down
29 changes: 29 additions & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ bindir="$rootdir/bin"
objdir="$builddir/obj"
gendir="$builddir/gen"
slnpath="$rootdir/CppSharp.sln"
artifacts="$rootdir/artifacts"
oshost=""
os=""
test=
Expand Down Expand Up @@ -43,6 +44,11 @@ build()
fi
}

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

generate()
{
download_llvm
Expand All @@ -60,6 +66,19 @@ restore()
$msbuild $slnpath -p:Configuration=$configuration -p:Platform=$platform -v:$verbosity -t:restore -nologo
}

prepack()
{
find_msbuild
$msbuild $slnpath -t:prepack -p:Configuration=$configuration -p:Platform=$platform -v:$verbosity -nologo
}

pack()
{
find_msbuild
$msbuild -t:restore $rootdir/src/Package/CppSharp.Package.csproj -p:Configuration=$configuration -p:Platform=$platform
$msbuild -t:pack $rootdir/src/Package/CppSharp.Package.csproj -p:Configuration=$configuration -p:Platform=$platform -p:PackageOutputPath=$rootdir/artifacts
}

test()
{
dotnet test {$bindir/${configuration}_$platform,$gendir/*}/*.Tests*.dll --nologo
Expand Down Expand Up @@ -172,6 +191,7 @@ while [[ $# > 0 ]]; do
;;
-ci)
ci=true
export CI=true
;;
-build_only)
build_only=true
Expand All @@ -187,6 +207,15 @@ case "$cmd" in
generate)
generate
;;
generate_config)
generate_config
;;
prepack)
prepack
;;
pack)
pack
;;
restore)
restore
;;
Expand Down
23 changes: 0 additions & 23 deletions build/nuget/.vscode/launch.json

This file was deleted.

17 changes: 0 additions & 17 deletions build/nuget/TODO.txt

This file was deleted.

125 changes: 0 additions & 125 deletions build/nuget/build.cake

This file was deleted.

Loading

0 comments on commit 62e9119

Please sign in to comment.