Skip to content

Commit

Permalink
build and package fsc using .NET Core Sdk
Browse files Browse the repository at this point in the history
- add helper script to install .NET Core Sdk (only if needed)
- build `Fsc.netcore.fspro with `fsc-proto`
- publish Fsc using .NET Core Sdk as framework dependent app
- create `Microsoft.FSharp.Compiler.Sdk.netcore` package
- add build script using `dotnet msbuild`
- run when `netcoresdk` arg is passed to build script (`build.cmd`)
- add end to end tests to check created package
- add examples of .net core sdk projects (lib/console)
  • Loading branch information
enricosada committed Jan 24, 2017
1 parent 877aed4 commit c2d6d4f
Show file tree
Hide file tree
Showing 39 changed files with 1,286 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ times
source_link.json
.vs/
/VSRelease/net40/bin
.dotnetsdk
scripts/dotnet-install.*.ps1
src/fsharp/FSharp.Compiler.Sdk.netcore.nuget/bin
1 change: 1 addition & 0 deletions DotnetCoreSdkVersion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0-preview4-004233
68 changes: 68 additions & 0 deletions build-using-netcore-sdk.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<Project ToolsVersion="15.0" InitialTargets="CheckPrereqs" DefaultTargets="All">

<Target Name="Init">
<!-- Define global properties -->

<PropertyGroup>
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
<NuGetPackageRoot>$(RepoRoot)/packages</NuGetPackageRoot>
</PropertyGroup>
</Target>

<Import Project="build/CheckPrereqs.proj" />
<Import Project="build/Prepare.proj" />
<Import Project="build/Compile.proj" />
<Import Project="build/Package.proj" />
<Import Project="build/Test.E2E.proj" />

<Target Name="All"
DependsOnTargets="Prepare;
Compile;
Package;
TestE2E;" />
<Target Name="Clean"
DependsOnTargets="CleanSrcLockFiles;
CleanCompile;
CleanPackage;
CleanTestE2E;" />

<!--
# MAIN TARGETS
- `CheckPrereqs` check prerequisites, always runs as the first target
- `Prepare` restore projects
- `Compile` build all projects
- `Package` create the nuget packages
- `TestE2E` run End to End tests, using built nupkgs
- `Clean` remove all build artifacts
Build pipeline (target `All`) is:
CheckPrereqs -> Prepare -> Compile -> Package -> TestE2E
# PARAMETERS
these can be passed as msbuild properties (/p) or env var
If not set, defaults are used.
| Name | Description | Example |
|~~~~~~~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
| PackageVersion | Full version to use for nupkgs | "1.0.0-rc-170124" |
| Packages | List of nupkgs to generate, by default all. | "Microsoft.FSharp.Compiler.Sdk.netcore" |
| NupkgOutputDirectory | Output Dir of generated nupkgs | A directory full path |
# TARGETS
- `RestoreSrcPackages` restore the /src projects
- `CleanSrcLockFiles` clean the nuget restore lock files (so `RestoreSrcPackages` can be run again)
- `BuildFsc` compile fsc
- `PublishFsc` publish fsc as framework dependent deployment (ready for `dotnet /path/to/fsc.dll`)
- `RunPackageTests` test the built packages in real projects E2E
- the `RestoreTestPackages` and `CleanTestLockFiles` manage the restore of test projects
-->

</Project>
30 changes: 29 additions & 1 deletion build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ echo Build and run a subset of test suites
echo.
echo Usage:
echo.
echo build.cmd ^<all^|net40^|coreclr^|pcls^|vs^>
echo build.cmd ^<all^|net40^|coreclr^|netcoresdk^|pcls^|vs^>
echo ^<proto^|protofx^>
echo ^<ci^|ci_part1^|ci_part2^|ci_part3^|microbuild^>
echo ^<debug^|release^>
Expand All @@ -40,6 +40,7 @@ echo. build.cmd net40 test (build and test net40)
echo. build.cmd coreclr test (build and test net40)
echo. build.cmd vs test (build and test net40)
echo. build.cmd all test (build and test net40)
echo. build.cmd coreclr netcoresdk (build compiler for .NET Core using .NET Core Sdk)
echo. build.cmd nobuild test include Conformance (run only tests marked with Conformance category)
echo. build.cmd nobuild test include Expensive (run only tests marked with Expensive category)
echo.
Expand All @@ -57,6 +58,7 @@ set BUILD_PROTO=0
set BUILD_PHASE=1
set BUILD_NET40=0
set BUILD_CORECLR=0
set BUILD_CORECLR_USING_NETCORESDK=0
set BUILD_PORTABLE=0
set BUILD_VS=0
set BUILD_CONFIG=release
Expand Down Expand Up @@ -231,6 +233,7 @@ if /i '%ARG%' == 'ci_part3' (
set BUILD_PROTO=1
set BUILD_NET40=1
set BUILD_CORECLR=1
set BUILD_CORECLR_USING_NETCORESDK=1

set TEST_CORECLR_FSHARP_SUITE=1
set TEST_CORECLR_COREUNIT_SUITE=1
Expand Down Expand Up @@ -328,6 +331,10 @@ if /i '%ARG%' == 'publicsign' (
set BUILD_PUBLICSIGN=1
)

if /i '%ARG%' == 'netcoresdk' (
set BUILD_CORECLR_USING_NETCORESDK=1
)

goto :EOF
:: Note: "goto :EOF" returns from an in-batchfile "call" command
:: in preference to returning from the entire batch file.
Expand All @@ -345,6 +352,7 @@ echo BUILD_PROTO=%BUILD_PROTO%
echo BUILD_PROTO_WITH_CORECLR_LKG=%BUILD_PROTO_WITH_CORECLR_LKG%
echo BUILD_NET40=%BUILD_NET40%
echo BUILD_CORECLR=%BUILD_CORECLR%
echo BUILD_CORECLR_USING_NETCORESDK=%BUILD_CORECLR_USING_NETCORESDK%
echo BUILD_PORTABLE=%BUILD_PORTABLE%
echo BUILD_VS=%BUILD_VS%
echo BUILD_SETUP=%BUILD_SETUP%
Expand Down Expand Up @@ -542,6 +550,26 @@ if '%BUILD_PHASE%' == '1' (
@if ERRORLEVEL 1 echo Error: '%_msbuildexe% %msbuildflags% build-everything.proj /p:Configuration=%BUILD_CONFIG% %BUILD_DIAG% /p:BUILD_PUBLICSIGN=%BUILD_PUBLICSIGN%' failed && goto :failure
)

echo ---------------- Done with build, building using .net core sdk -----------

if '%BUILD_CORECLR_USING_NETCORESDK%' == '1' (

setlocal enableDelayedExpansion

call .\scripts\use_dotnet_core_sdk.bat
@if ERRORLEVEL 1 echo Error: scripts\use_dotnet_core_sdk.bat && endlocal && goto :failure

echo .NET Core Sdk version:
dotnet --version
@if ERRORLEVEL 1 echo Error: dotnet --version && endlocal && goto :failure

dotnet msbuild build-using-netcore-sdk.proj /p:Configuration=%BUILD_CONFIG% /t:All /v:n
@if ERRORLEVEL 1 echo Error: dotnet msbuild build-using-netcore-sdk.proj && endlocal && goto :failure

endlocal

)

echo ---------------- Done with build, starting update/prepare ---------------

if '%BUILD_NET40%' == '1' (
Expand Down
34 changes: 34 additions & 0 deletions build/CheckPrereqs.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project ToolsVersion="15.0">

<Target Name="CheckPrereqs">
<!-- Check .NET Core SDK is avaiable in PATH -->

<Exec Command="dotnet --version" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="InstalledDotnetCoreSdkVersion" />
</Exec>

<Message Text="Installed sdk version $(InstalledDotnetCoreSdkVersion)" Importance="High" />

<!-- Check the .NET Core SDK version is compatible (same branch) with required version -->
<PropertyGroup>
<_ExpectedDotnetCoreSdkBranch>1.0.0-preview4</_ExpectedDotnetCoreSdkBranch>
</PropertyGroup>

<Error Text="Expected .NET Core Sdk ~$(_ExpectedDotnetCoreSdkBranch) but was $(InstalledDotnetCoreSdkVersion)"
Condition=" !$(InstalledDotnetCoreSdkVersion.StartsWith('$(_ExpectedDotnetCoreSdkBranch)')) " />
</Target>

<Target Name="RequireCoreclrBin"
DependsOnTargets="Init">
<!-- Check the coreclr binaries built with main build script is avaiable -->
<!-- DEFINE $(CoreclrReleaseDir): The directory of coreclr binaries built by main script -->

<PropertyGroup>
<CoreclrReleaseDir>$(RepoRoot)/$(Configuration)/coreclr/bin</CoreclrReleaseDir>
</PropertyGroup>

<Error Text="The '$(CoreclrReleaseDir)' is required, build it using `build.cmd coreclr` "
Condition=" !Exists('$(CoreclrReleaseDir)') " />
</Target>

</Project>
42 changes: 42 additions & 0 deletions build/Compile.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<Project ToolsVersion="15.0">

<Target Name="Compile"
DependsOnTargets="Prepare;
BuildFsc" />

<Target Name="BuildFsc"
DependsOnTargets="Init;
RequireCoreclrBin" > <!-- the fsc proj expect the FSharp.Core already built -->

<Exec Command='dotnet build "$(RepoRoot)/src/fsharp/Fsc/Fsc.netcore.fsproj" -c $(Configuration)' />
</Target>

<Target Name="PublishFsc"
DependsOnTargets="Init;RequireCoreclrBin;BuildFsc" >
<!-- Create a framework dependent version of fsc -->
<!-- DEFINE $(FscPublishDirectoryNetCoreApp1_0): The directory who contains the framework dependent version of fsc -->

<Exec Command='dotnet publish "$(RepoRoot)/src/fsharp/Fsc/Fsc.netcore.fsproj" -c $(Configuration)' />

<PropertyGroup>
<FscPublishDirectoryNetCoreApp1_0>$(RepoRoot)/src/fsharp/Fsc/bin/$(Configuration)/netcoreapp1.0/publish</FscPublishDirectoryNetCoreApp1_0>
</PropertyGroup>

<!-- REMARK: The generated fsc.dll doesnt work yet.
Reuse the fsc.exe already built until it's fixed -->
<Copy SourceFiles="$(CoreclrReleaseDir)/fsc.exe;
$(CoreclrReleaseDir)/fsc.pdb;"
DestinationFiles="$(FscPublishDirectoryNetCoreApp1_0)/fsc.dll;
$(FscPublishDirectoryNetCoreApp1_0)/fsc.pdb;"
OverwriteReadOnlyFiles="true" />

</Target>

<Target Name="CleanCompile"
DependsOnTargets="Init">

<RemoveDir Directories="$(RepoRoot)/src/fsharp/Fsc/bin" />
<RemoveDir Directories="$(RepoRoot)/src/fsharp/Fsc/obj" />
</Target>

</Project>
57 changes: 57 additions & 0 deletions build/Package.Nupkg.Microsoft.FSharp.Compiler.Sdk.netcore.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<Project ToolsVersion="15.0">

<ItemGroup>
<SetupNugetPackagesDependsOn Include="SetupNugetPackages_MicrosoftFSharpCompilerSdknetcore" />
</ItemGroup>

<Target Name="SetupNugetPackages_MicrosoftFSharpCompilerSdknetcore"
Condition=" '$(Packages)' == '' or $(Packages.Contains('Microsoft.FSharp.Compiler.Sdk.netcore'))"
DependsOnTargets="Init;RequireCoreclrBin;PublishFsc" >
<PropertyGroup>
<_PackageProjectDir>$(RepoRoot)/src/fsharp/FSharp.Compiler.Sdk.netcore.nuget</_PackageProjectDir>
<_PackageName>Microsoft.FSharp.Compiler.Sdk.netcore</_PackageName>
</PropertyGroup>
<!-- Specify the 'Microsoft.FSharp.Compiler.Sdk.netcore' nuget package content -->

<!-- Package content -->
<ItemGroup>
<!-- the published fsc for netcoreapp1.0 -->
<_FscPublishOutputFiles Include="$(FscPublishDirectoryNetCoreApp1_0)/**/*" />
<_FsharpBuildFiles Include="$(CoreclrReleaseDir)/FSharp.Build.*" />
<_PackageProjectFiles Include="$(_PackageProjectDir)/**/*"
Exclude="$(_PackageProjectDir)/*.nuspec;$(_PackageProjectDir)/bin/**/*" />

<!-- the fsc published (netcoreapp1.0) files -->
<NugetPackageLayout Include="@(_FscPublishOutputFiles)">
<PackageName>$(_PackageName)</PackageName>
<PackageRelativePath>build/netcoreapp1.0/%(RecursiveDir)%(FileName)%(Extension)</PackageRelativePath>
</NugetPackageLayout>

<!-- the FSharp.Build assembly who contains msbuild tasks -->
<NugetPackageLayout Include="@(_FsharpBuildFiles)">
<PackageName>$(_PackageName)</PackageName>
<PackageRelativePath>build/netcoreapp1.0/%(RecursiveDir)%(FileName)%(Extension)</PackageRelativePath>
</NugetPackageLayout>

<!-- The package content files, except the nuspec -->
<NugetPackageLayout Include="@(_PackageProjectFiles)">
<PackageName>$(_PackageName)</PackageName>
<PackageRelativePath>%(RecursiveDir)%(FileName)%(Extension)</PackageRelativePath>
</NugetPackageLayout>
</ItemGroup>

<PropertyGroup>
<PackageVersion Condition="'$(PackageVersion)' == ''" >$(NuGetPerBuildPreReleaseVersion)</PackageVersion>
</PropertyGroup>

<!-- Package metadata -->
<ItemGroup>
<NugetPackageDef Include="$(_PackageName)">
<NuspecFile>$(_PackageProjectDir)/$(_PackageName).nuspec</NuspecFile>
<Version>$(PackageVersion)</Version>
</NugetPackageDef>
</ItemGroup>

</Target>

</Project>
90 changes: 90 additions & 0 deletions build/Package.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<Project ToolsVersion="15.0">

<Import Project="../src/FSharp.nugets.props" />

<!-- Import all nuget package definitions -->
<Import Project="Package.Nupkg.Microsoft.FSharp.Compiler.Sdk.netcore.proj" />

<Target Name="Package"
DependsOnTargets="Prepare;
Compile;
GenerateNugetPackages" />

<Target Name="SetupNugetPackagesProperties"
DependsOnTargets="Init" >
<!-- Global properties required for nuget packages creation, like output dir and layout dir -->

<PropertyGroup>
<NupkgOutputDirectory Condition=" '$(NupkgOutputDirectory)' == '' ">$(RepoRoot)/$(Configuration)/artifacts</NupkgOutputDirectory>
<PackagingBuildBasePath>$(RepoRoot)/$(Configuration)/forPackaging</PackagingBuildBasePath>
</PropertyGroup>
</Target>

<Target Name="SetupNugetPackages"
DependsOnTargets="Init;
SetupNugetPackagesProperties;
@(SetupNugetPackagesDependsOn)" />

<Target Name="LayoutNugetPackages"
DependsOnTargets="Init;SetupNugetPackagesProperties;SetupNugetPackages"
Outputs="%(NugetPackageLayout.PackageName)" >
<!-- Create the directory with the content of nuget packages, ready for nuget pack -->

<PropertyGroup>
<_PackageName>%(NugetPackageLayout.PackageName)</_PackageName>
</PropertyGroup>

<Copy SourceFiles="%(NugetPackageLayout.Identity)"
Condition=" '%(PackageName)' == '$(_PackageName)' "
DestinationFiles="$(PackagingBuildBasePath)/%(PackageName)/%(PackageRelativePath)"
SkipUnchangedFiles="true" />
</Target>

<Target Name="GenerateNugetPackages"
DependsOnTargets="Init;LayoutNugetPackages"
Outputs="$(NupkgDirectory)/%(NugetPackageDef.Identity).%(NugetPackageDef.Version).nupkg" >
<!-- Generate the nuget packages, doing nuget pack of prepared layour dir and setting metadata -->

<PropertyGroup>
<PackageLicenceUrl Condition="'$(PackageLicenceUrl)' == ''">https://github.com/Microsoft/visualfsharp/blob/master/License.txt</PackageLicenceUrl>
<PackageProjectUrl Condition="'$(PackageProjectUrl)' == ''">https://github.com/Microsoft/visualfsharp</PackageProjectUrl>
<PackageVersion Condition="'$(PackageVersion)' == ''" >$(NuGetPerBuildPreReleaseVersion)</PackageVersion>
<PackageAuthors Condition="'$(PackageAuthors)' == ''" >Microsoft</PackageAuthors>
<PackageTags Condition="'$(PackageTags)' == ''" >Visual F# Compiler FSharp coreclr functional programming</PackageTags>
</PropertyGroup>

<PropertyGroup>
<_CurrentPackageName>%(NugetPackageDef.Identity)</_CurrentPackageName>
</PropertyGroup>

<!-- Prepare args for nuget pack -->

<ItemGroup>
<_NuspecProperties Include='licenseUrl="$(PackageLicenceUrl)"' />
<_NuspecProperties Include='projectUrl="$(PackageProjectUrl)"' />
<_NuspecProperties Include='version=$(PackageVersion)' />
<_NuspecProperties Include='authors="$(PackageAuthors)"' />
<_NuspecProperties Include='tags="$(PackageTags)"' />
</ItemGroup>

<PropertyGroup>
<!-- the nuget pack output path must be relative, absolute is ignored -->
<_NupkgDirectory>.$([MSBuild]::MakeRelative( $(MSBuildProjectDirectory), "$(NupkgOutputDirectory)/" ))</_NupkgDirectory>

<!-- the nuget pack command fails if there is a trailing directory separator -->
<_NupkgDirectory>$(_NupkgDirectory.TrimEnd('\').TrimEnd('/'))</_NupkgDirectory>
</PropertyGroup>

<Exec Command="dotnet nuget pack &quot;@(NugetPackageDef -> '%(NuspecFile)')&quot; --base-path &quot;$(PackagingBuildBasePath)/$(_CurrentPackageName)&quot; --exclude-empty-directories --properties @(_NuspecProperties) --output-directory &quot;$(_NupkgDirectory)&quot;"
Condition=" '$(_CurrentPackageName)' == '%(NugetPackageDef.Identity)' "
/>
</Target>

<Target Name="CleanPackage"
DependsOnTargets="Init;SetupNugetPackagesProperties;">

<RemoveDir Directories="$(PackagingBuildBasePath)"
Condition=" '$(PackagingBuildBasePath)' != '' " />
</Target>

</Project>
Loading

0 comments on commit c2d6d4f

Please sign in to comment.