提交 fce4e9e2 编写于 作者: D Don Syme

Merge commit '0fb398da' into feature/ext

......@@ -16,6 +16,7 @@ artifacts/
src/Compiler/Checking/**/*.fs
src/Compiler/CodeGen/**/*.fs
src/Compiler/DependencyManager/**/*.fs
src/Compiler/Facilities/**/*.fs
src/Compiler/Interactive/**/*.fs
src/Compiler/Legacy/**/*.fs
src/Compiler/Optimize/**/*.fs
......
......@@ -61,6 +61,7 @@ param (
[string]$officialSkipTests = "false",
[switch]$noVisualStudio,
[switch]$sourceBuild,
[switch]$skipBuild,
[parameter(ValueFromRemainingArguments = $true)][string[]]$properties)
......@@ -114,6 +115,7 @@ function Print-Usage() {
Write-Host " -useGlobalNuGetCache Use global NuGet cache."
Write-Host " -noVisualStudio Only build fsc and fsi as .NET Core applications. No Visual Studio required. '-configuration', '-verbosity', '-norestore', '-rebuild' are supported."
Write-Host " -sourceBuild Simulate building for source-build."
Write-Host " -skipbuild Skip building product"
Write-Host ""
Write-Host "Command line arguments starting with '/p:' are passed through to MSBuild."
}
......@@ -458,7 +460,7 @@ try {
}
$script:BuildMessage = "Failure building product"
if ($restore -or $build -or $rebuild -or $pack -or $sign -or $publish) {
if ($restore -or $build -or $rebuild -or $pack -or $sign -or $publish -and -not $skipBuild) {
if ($noVisualStudio) {
BuildSolution "FSharp.sln"
}
......
......@@ -12,78 +12,96 @@ open Internal.Utilities.FSharpEnvironment
type AssemblyResolutionProbe = delegate of Unit -> seq<string>
/// Type that encapsulates AssemblyResolveHandler for managed packages
type AssemblyResolveHandlerCoreclr (assemblyProbingPaths: AssemblyResolutionProbe option) as this =
let assemblyLoadContextType: Type = Type.GetType("System.Runtime.Loader.AssemblyLoadContext, System.Runtime.Loader", false)
type AssemblyResolveHandlerCoreclr(assemblyProbingPaths: AssemblyResolutionProbe option) as this =
let loadContextType =
Type.GetType("System.Runtime.Loader.AssemblyLoadContext, System.Runtime.Loader", false)
let loadFromAssemblyPathMethod =
assemblyLoadContextType.GetMethod("LoadFromAssemblyPath", [| typeof<string> |])
loadContextType.GetMethod("LoadFromAssemblyPath", [| typeof<string> |])
let eventInfo, handler, defaultAssemblyLoadContext =
let eventInfo = assemblyLoadContextType.GetEvent("Resolving")
let mi =
let gmi = this.GetType().GetMethod("ResolveAssemblyNetStandard", BindingFlags.Instance ||| BindingFlags.NonPublic)
gmi.MakeGenericMethod(assemblyLoadContextType)
let eventInfo = loadContextType.GetEvent("Resolving")
eventInfo,
Delegate.CreateDelegate(eventInfo.EventHandlerType, this, mi),
assemblyLoadContextType.GetProperty("Default", BindingFlags.Static ||| BindingFlags.Public).GetValue(null, null)
let handler, defaultAssemblyLoadContext =
let ti = typeof<AssemblyResolveHandlerCoreclr>
let gmi =
ti.GetMethod("ResolveAssemblyNetStandard", BindingFlags.Instance ||| BindingFlags.NonPublic)
let mi = gmi.MakeGenericMethod(loadContextType)
let del = Delegate.CreateDelegate(eventInfo.EventHandlerType, this, mi)
let prop =
loadContextType
.GetProperty("Default", BindingFlags.Static ||| BindingFlags.Public)
.GetValue(null, null)
del, prop
do eventInfo.AddEventHandler(defaultAssemblyLoadContext, handler)
member _.ResolveAssemblyNetStandard (ctxt: 'T) (assemblyName: AssemblyName): Assembly =
member _.ResolveAssemblyNetStandard (ctxt: 'T) (assemblyName: AssemblyName) : Assembly =
let loadAssembly path =
loadFromAssemblyPathMethod.Invoke(ctxt, [| path |]) :?> Assembly
let assemblyPaths =
match assemblyProbingPaths with
| None -> Seq.empty<string>
| Some assemblyProbingPaths -> assemblyProbingPaths.Invoke()
| Some assemblyProbingPaths -> assemblyProbingPaths.Invoke()
try
// args.Name is a displayname formatted assembly version.
// E.g: "System.IO.FileSystem, Version=4.1.1.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a"
let simpleName = assemblyName.Name
let assemblyPathOpt = assemblyPaths |> Seq.tryFind(fun path -> Path.GetFileNameWithoutExtension(path) = simpleName)
let assemblyPathOpt =
assemblyPaths
|> Seq.tryFind (fun path -> Path.GetFileNameWithoutExtension(path) = simpleName)
match assemblyPathOpt with
| Some path -> loadAssembly path
| None -> Unchecked.defaultof<Assembly>
with | _ -> Unchecked.defaultof<Assembly>
with _ ->
Unchecked.defaultof<Assembly>
interface IDisposable with
member _x.Dispose() =
eventInfo.RemoveEventHandler(defaultAssemblyLoadContext, handler)
/// Type that encapsulates AssemblyResolveHandler for managed packages
type AssemblyResolveHandlerDeskTop (assemblyProbingPaths: AssemblyResolutionProbe option) =
type AssemblyResolveHandlerDeskTop(assemblyProbingPaths: AssemblyResolutionProbe option) =
let resolveAssemblyNET (assemblyName: AssemblyName): Assembly =
let loadAssembly assemblyPath =
Assembly.LoadFrom(assemblyPath)
let resolveAssemblyNET (assemblyName: AssemblyName) : Assembly =
let assemblyPaths =
match assemblyProbingPaths with
| None -> Seq.empty<string>
| Some assemblyProbingPaths -> assemblyProbingPaths.Invoke()
| Some assemblyProbingPaths -> assemblyProbingPaths.Invoke()
try
// args.Name is a displayname formatted assembly version.
// E.g: "System.IO.FileSystem, Version=4.1.1.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a"
let simpleName = assemblyName.Name
let assemblyPathOpt = assemblyPaths |> Seq.tryFind(fun path -> Path.GetFileNameWithoutExtension(path) = simpleName)
let assemblyPathOpt =
assemblyPaths
|> Seq.tryFind (fun path -> Path.GetFileNameWithoutExtension(path) = simpleName)
match assemblyPathOpt with
| Some path -> loadAssembly path
| Some path -> Assembly.LoadFrom path
| None -> Unchecked.defaultof<Assembly>
with | _ -> Unchecked.defaultof<Assembly>
with _ ->
Unchecked.defaultof<Assembly>
let handler =
ResolveEventHandler(fun _ (args: ResolveEventArgs) -> resolveAssemblyNET (AssemblyName(args.Name)))
let handler = ResolveEventHandler(fun _ (args: ResolveEventArgs) -> resolveAssemblyNET (AssemblyName(args.Name)))
do AppDomain.CurrentDomain.add_AssemblyResolve(handler)
do AppDomain.CurrentDomain.add_AssemblyResolve (handler)
interface IDisposable with
member _x.Dispose() =
AppDomain.CurrentDomain.remove_AssemblyResolve(handler)
AppDomain.CurrentDomain.remove_AssemblyResolve (handler)
type AssemblyResolveHandler internal (assemblyProbingPaths: AssemblyResolutionProbe option) =
......@@ -93,7 +111,7 @@ type AssemblyResolveHandler internal (assemblyProbingPaths: AssemblyResolutionPr
else
new AssemblyResolveHandlerDeskTop(assemblyProbingPaths) :> IDisposable
new (assemblyProbingPaths: AssemblyResolutionProbe) = new AssemblyResolveHandler(Option.ofObj assemblyProbingPaths)
new(assemblyProbingPaths: AssemblyResolutionProbe) = new AssemblyResolveHandler(Option.ofObj assemblyProbingPaths)
interface IDisposable with
member _.Dispose() = handler.Dispose()
......@@ -16,14 +16,17 @@ open FSharp.Compiler.IO
type NativeResolutionProbe = delegate of Unit -> seq<string>
/// Type that encapsulates Native library probing for managed packages
type NativeDllResolveHandlerCoreClr (nativeProbingRoots: NativeResolutionProbe option) =
type NativeDllResolveHandlerCoreClr(nativeProbingRoots: NativeResolutionProbe option) =
let nativeLibraryTryLoad =
let nativeLibraryType: Type = Type.GetType("System.Runtime.InteropServices.NativeLibrary, System.Runtime.InteropServices", false)
nativeLibraryType.GetMethod("TryLoad", [| typeof<string>; typeof<IntPtr>.MakeByRefType() |])
let nativeLibraryType: Type =
Type.GetType("System.Runtime.InteropServices.NativeLibrary, System.Runtime.InteropServices", false)
nativeLibraryType.GetMethod("TryLoad", [| typeof<string>; typeof<IntPtr>.MakeByRefType () |])
let loadNativeLibrary path =
let arguments = [| path:>obj; IntPtr.Zero:>obj |]
let arguments = [| path :> obj; IntPtr.Zero :> obj |]
if nativeLibraryTryLoad.Invoke(null, arguments) :?> bool then
arguments[1] :?> IntPtr
else
......@@ -32,13 +35,20 @@ type NativeDllResolveHandlerCoreClr (nativeProbingRoots: NativeResolutionProbe o
let probingFileNames (name: string) =
// coreclr native library probing algorithm: https://github.com/dotnet/coreclr/blob/9773db1e7b1acb3ec75c9cc0e36bd62dcbacd6d5/src/System.Private.CoreLib/shared/System/Runtime/Loader/LibraryNameVariation.Unix.cs
let isRooted = Path.IsPathRooted name
let useSuffix s = not (name.Contains(s + ".") || name.EndsWith(s)) // linux devs often append version # to libraries I.e mydll.so.5.3.2
let usePrefix = name.IndexOf(Path.DirectorySeparatorChar) = -1 // If name has directory information no add no prefix
&& name.IndexOf(Path.AltDirectorySeparatorChar) = -1
&& name.IndexOf(Path.PathSeparator) = -1
&& name.IndexOf(Path.VolumeSeparatorChar) = -1
let useSuffix s =
not (name.Contains(s + ".") || name.EndsWith(s)) // linux devs often append version # to libraries I.e mydll.so.5.3.2
let usePrefix =
name.IndexOf(Path.DirectorySeparatorChar) = -1 // If name has directory information no add no prefix
&& name.IndexOf(Path.AltDirectorySeparatorChar) = -1
&& name.IndexOf(Path.PathSeparator) = -1
&& name.IndexOf(Path.VolumeSeparatorChar) = -1
let prefix = [| "lib" |]
let suffix = [|
let suffix =
[|
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
".dll"
".exe"
......@@ -49,72 +59,79 @@ type NativeDllResolveHandlerCoreClr (nativeProbingRoots: NativeResolutionProbe o
|]
[|
yield name // Bare name
yield name // Bare name
if not isRooted then
for s in suffix do
if useSuffix s then // Suffix without prefix
if useSuffix s then // Suffix without prefix
yield (sprintf "%s%s" name s)
if usePrefix then
for p in prefix do // Suffix with prefix
for p in prefix do // Suffix with prefix
yield (sprintf "%s%s%s" p name s)
elif usePrefix then
for p in prefix do // Prefix
for p in prefix do // Prefix
yield (sprintf "%s%s" p name)
|]
let resolveUnmanagedDll (_: Assembly) (name: string): IntPtr =
let resolveUnmanagedDll (_: Assembly) (name: string) : IntPtr =
// Enumerate probing roots looking for a dll that matches the probing name in the probed locations
let probeForNativeLibrary root rid name =
// Look for name in root
probingFileNames name |> Array.tryPick(fun name ->
probingFileNames name
|> Array.tryPick (fun name ->
let path = Path.Combine(root, "runtimes", rid, "native", name)
if FileSystem.FileExistsShim(path) then
Some path
else
None)
if FileSystem.FileExistsShim(path) then Some path else None)
let probe =
match nativeProbingRoots with
| None -> None
| Some nativeProbingRoots ->
| Some nativeProbingRoots ->
nativeProbingRoots.Invoke()
|> Seq.tryPick(fun root ->
probingFileNames name |> Seq.tryPick(fun name ->
|> Seq.tryPick (fun root ->
probingFileNames name
|> Seq.tryPick (fun name ->
let path = Path.Combine(root, name)
if FileSystem.FileExistsShim(path) then
Some path
else
RidHelpers.probingRids |> Seq.tryPick(fun rid -> probeForNativeLibrary root rid name)))
RidHelpers.probingRids
|> Seq.tryPick (fun rid -> probeForNativeLibrary root rid name)))
match probe with
| Some path -> loadNativeLibrary(path)
| Some path -> loadNativeLibrary (path)
| None -> IntPtr.Zero
// netstandard 2.1 has this property, unfortunately we don't build with that yet
//public event Func<Assembly, string, IntPtr> ResolvingUnmanagedDll
let assemblyLoadContextType: Type = Type.GetType("System.Runtime.Loader.AssemblyLoadContext, System.Runtime.Loader", false)
let assemblyLoadContextType: Type =
Type.GetType("System.Runtime.Loader.AssemblyLoadContext, System.Runtime.Loader", false)
let eventInfo, handler, defaultAssemblyLoadContext =
assemblyLoadContextType.GetEvent("ResolvingUnmanagedDll"),
Func<Assembly, string, IntPtr> resolveUnmanagedDll,
assemblyLoadContextType.GetProperty("Default", BindingFlags.Static ||| BindingFlags.Public).GetValue(null, null)
assemblyLoadContextType
.GetProperty("Default", BindingFlags.Static ||| BindingFlags.Public)
.GetValue(null, null)
do eventInfo.AddEventHandler(defaultAssemblyLoadContext, handler)
interface IDisposable with
member _x.Dispose() = eventInfo.RemoveEventHandler(defaultAssemblyLoadContext, handler)
member _x.Dispose() =
eventInfo.RemoveEventHandler(defaultAssemblyLoadContext, handler)
type NativeDllResolveHandler (nativeProbingRoots: NativeResolutionProbe option) =
type NativeDllResolveHandler(nativeProbingRoots: NativeResolutionProbe option) =
let handler: IDisposable option =
if isRunningOnCoreClr then
Some (new NativeDllResolveHandlerCoreClr(nativeProbingRoots) :> IDisposable)
Some(new NativeDllResolveHandlerCoreClr(nativeProbingRoots) :> IDisposable)
else
None
let appendPathSeparator (p: string) =
let separator = string Path.PathSeparator
if not(p.EndsWith(separator, StringComparison.OrdinalIgnoreCase)) then
if not (p.EndsWith(separator, StringComparison.OrdinalIgnoreCase)) then
p + separator
else
p
......@@ -124,17 +141,20 @@ type NativeDllResolveHandler (nativeProbingRoots: NativeResolutionProbe option)
let addProbeToProcessPath probePath =
let probe = appendPathSeparator probePath
let path = appendPathSeparator (Environment.GetEnvironmentVariable("PATH"))
if not (path.Contains(probe)) then
Environment.SetEnvironmentVariable("PATH", path + probe)
addedPaths.Add probe
let removeProbeFromProcessPath probePath =
if not(String.IsNullOrWhiteSpace(probePath)) then
if not (String.IsNullOrWhiteSpace(probePath)) then
let probe = appendPathSeparator probePath
let path = appendPathSeparator (Environment.GetEnvironmentVariable("PATH"))
if path.Contains(probe) then Environment.SetEnvironmentVariable("PATH", path.Replace(probe, ""))
new (nativeProbingRoots: NativeResolutionProbe) = new NativeDllResolveHandler(Option.ofObj nativeProbingRoots)
if path.Contains(probe) then
Environment.SetEnvironmentVariable("PATH", path.Replace(probe, ""))
new(nativeProbingRoots: NativeResolutionProbe) = new NativeDllResolveHandler(Option.ofObj nativeProbingRoots)
member internal _.RefreshPathsInEnvironment(roots: string seq) =
for probePath in roots do
......@@ -146,6 +166,7 @@ type NativeDllResolveHandler (nativeProbingRoots: NativeResolutionProbe option)
| None -> ()
| Some handler -> handler.Dispose()
let mutable probe:string = Unchecked.defaultof<string>
let mutable probe: string = Unchecked.defaultof<string>
while (addedPaths.TryTake(&probe)) do
removeProbeFromProcessPath probe
......@@ -754,7 +754,6 @@
<ProjectReference Include="$(MSBuildThisFileDirectory)..\FSharp.DependencyManager.Nuget\FSharp.DependencyManager.Nuget.fsproj" />
</ItemGroup>
<ItemGroup Condition="'$(FSHARPCORE_USE_PACKAGE)' != 'true'">
<ProjectReference Include="$(MSBuildThisFileDirectory)..\FSharp.Core\FSharp.Core.fsproj" />
</ItemGroup>
......
......@@ -15,6 +15,7 @@
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<UseStandardResourceNames>false</UseStandardResourceNames>
<PackageOutputPath>$(ArtifactsPackagesDir)\$(Configuration)</PackageOutputPath>
<ShouldUnsetParentConfigurationAndPlatform>false</ShouldUnsetParentConfigurationAndPlatform>
</PropertyGroup>
</Project>
......@@ -4,8 +4,7 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework Condition="'$(Configuration)' != 'Proto'">netstandard2.0</TargetFramework>
<TargetFrameworks Condition="'$(Configuration)' == 'Proto'">netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<AssemblyName>FSharp.Build</AssemblyName>
<NoWarn>$(NoWarn);75</NoWarn> <!-- InternalCommandLineOption -->
<AllowCrossTargeting>true</AllowCrossTargeting>
......
......@@ -11,6 +11,13 @@
<NoDefaultExcludes>true</NoDefaultExcludes>
</PropertyGroup>
<PropertyGroup>
<ArcadeSdkDir Condition="'$(ArcadeSdkDir)' == ''">$(NuGetPackageRoot)microsoft.dotnet.arcade.sdk\$(ArcadeSdkVersion)\</ArcadeSdkDir>
<_BuildReleasePackagesTargets>$(ArcadeSdkDir)tools\BuildReleasePackages.targets</_BuildReleasePackagesTargets>
</PropertyGroup>
<Import Project="$(_BuildReleasePackagesTargets)" />
<ItemGroup>
<NuspecProperty Include="fSharpCorePreviewPackageVersion=$(FSCorePackageVersionValue)-$(VersionSuffix)" />
<NuspecProperty Include="fSharpCorePackageVersion=$(FSCorePackageVersionValue)" />
......@@ -19,6 +26,36 @@
<NuspecProperty Include="artifactsPackagesDir=$(ArtifactsPackagesDir)" />
</ItemGroup>
<Target Name="Build" />
<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)..\fsi\fsiProject\fsi.fsproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)..\fsc\fscProject\fsc.fsproj" />
</ItemGroup>
<ItemGroup>
<DependentProjects Include="$(MSBuildThisFileDirectory)..\FSharp.Core\FSharp.Core.fsproj">
<AdditionalProperties>TargetFrameworks=netstandard2.1;netstandard2.0</AdditionalProperties>
</DependentProjects>
<DependentProjects Include="$(MSBuildThisFileDirectory)..\FSharp.Build\FSharp.Build.fsproj">
<AdditionalProperties>TargetFrameworks=netstandard2.0</AdditionalProperties>
</DependentProjects>
<DependentProjects Include="$(MSBuildThisFileDirectory)..\FSharp.Compiler.Interactive.Settings\FSharp.Compiler.Interactive.Settings.fsproj">
<AdditionalProperties>TargetFrameworks=netstandard2.0</AdditionalProperties>
</DependentProjects>
<DependentProjects Include="$(MSBuildThisFileDirectory)..\FSharp.DependencyManager.Nuget\FSharp.DependencyManager.Nuget.fsproj">
<AdditionalProperties>TargetFrameworks=netstandard2.0</AdditionalProperties>
</DependentProjects>
<DependentProjects Include="$(MSBuildThisFileDirectory)..\Compiler\FSharp.Compiler.Service.fsproj">
<AdditionalProperties>TargetFrameworks=netstandard2.0</AdditionalProperties>
</DependentProjects>
</ItemGroup>
<Target Name="PackDependentProjectsCore">
<MSBuild Projects="@(DependentProjects)" Targets="Pack" Properties="Restore=true;Pack=true;BUILD_PUBLICSIGN=$(BUILD_PUBLICSIGN)" />
</Target>
<Target Name="PackDependentProjects"
BeforeTargets="Build"
DependsOnTargets="PackDependentProjectsCore;PackageReleasePackages">
</Target>
</Project>
// See https://aka.ms/new-console-template for more information
// See https://aka.ms/new-console-template for more information
return 0;
\ No newline at end of file
......@@ -33,7 +33,7 @@
<NgenArchitecture>All</NgenArchitecture>
<NgenPriority>2</NgenPriority>
<Private>True</Private>
<AdditionalProperties>TargetFramework=$(DependencyTargetFramework)</AdditionalProperties>
<AdditionalProperties>TargetFramework=netstandard2.0</AdditionalProperties>
</ProjectReference>
<ProjectReference Include="$(FSharpSourcesRoot)\FSharp.Compiler.Interactive.Settings\FSharp.Compiler.Interactive.Settings.fsproj">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册