Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita490bbe

Browse files
authored
support .NET Standard 2.0 code generation (#3215)
1 parentd1ba9ff commita490bbe

File tree

13 files changed

+56
-85
lines changed

13 files changed

+56
-85
lines changed

‎src/absil/il.fs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,18 @@ let lazyMap f (x:Lazy<_>) =
5252
[<RequireQualifiedAccess>]
5353
typePrimaryAssembly=
5454
| Mscorlib
55-
| DotNetCore
55+
| System_Runtime
56+
| NetStandard
5657

5758
memberthis.Name=
5859
match thiswith
5960
| Mscorlib->"mscorlib"
60-
| DotNetCore->"System.Runtime"
61+
| System_Runtime->"System.Runtime"
62+
| NetStandard->"netstandard"
6163
static memberIsSomePrimaryAssembly n=
6264
n= PrimaryAssembly.Mscorlib.Name
63-
|| n= PrimaryAssembly.DotNetCore.Name
65+
|| n= PrimaryAssembly.System_Runtime.Name
66+
|| n= PrimaryAssembly.NetStandard.Name
6467

6568
// --------------------------------------------------------------------
6669
// Utilities: type names

‎src/absil/il.fsi‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ open System.Collections.Generic
1414
[<RequireQualifiedAccess>]
1515
typePrimaryAssembly=
1616
| Mscorlib
17-
| DotNetCore
17+
| System_Runtime
18+
| NetStandard
1819

1920
memberName:string
2021

‎src/fsharp/CompileOps.fs‎

Lines changed: 15 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,7 @@ let DefaultReferencesForScriptsAndOutOfProjectSources(assumeDotNetFramework) =
17081708
letSystemAssemblies()=
17091709
HashSet
17101710
[yield"mscorlib"
1711+
yield"netstandard"
17111712
yield"System.Runtime"
17121713
yield GetFSharpCoreLibraryName()
17131714
yield"System"
@@ -2187,7 +2188,7 @@ type TcConfigBuilder =
21872188
failwith"Expected a valid defaultFSharpBinariesDir"
21882189
{
21892190
#if COMPILER_SERVICE_ASSUMES_DOTNETCORE_COMPILATION
2190-
primaryAssembly= PrimaryAssembly.DotNetCore// defaut value, can be overridden using the command line switch
2191+
primaryAssembly= PrimaryAssembly.System_Runtime// defaut value, can be overridden using the command line switch
21912192
#else
21922193
primaryAssembly= PrimaryAssembly.Mscorlib// defaut value, can be overridden using the command line switch
21932194
#endif
@@ -2600,26 +2601,23 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
26002601
AssemblyReference(range0, GetDefaultFSharpCoreReference(), None), None
26012602
|_-> res
26022603

2603-
// If either mscorlib.dll/System.Runtime.dll or FSharp.Core.dll are explicitly specified then we require the --noframework flag.
2604+
// If either mscorlib.dll/System.Runtime.dll/netstandard.dll or FSharp.Core.dll are explicitly specified then we require the --noframework flag.
26042605
// The reason is that some non-default frameworks may not have the default dlls. For example, Client profile does
26052606
// not have System.Web.dll.
26062607
doif((primaryAssemblyExplicitFilenameOpt.IsSome|| fslibExplicitFilenameOpt.IsSome)&& data.framework)then
26072608
error(Error(FSComp.SR.buildExplicitCoreLibRequiresNoFramework("--noframework"),rangeStartup))
26082609

2609-
letclrRootValue,(mscorlibMajorVersion,targetFrameworkVersionValue),primaryAssemblyIsSilverlight=
2610+
letclrRootValue,targetFrameworkVersionValue=
26102611
match primaryAssemblyExplicitFilenameOptwith
26112612
| Some(primaryAssemblyFilename)->
26122613
letfilename= ComputeMakePathAbsolute data.implicitIncludeDir primaryAssemblyFilename
26132614
try
26142615
use ilReader= OpenILBinary(filename,data.optimizeForMemory,data.openBinariesInMemory,None,None, data.shadowCopyReferences)
26152616
letilModule= ilReader.ILModuleDef
26162617
match ilModule.ManifestOfAssembly.Versionwith
2617-
| Some(v1,v2,v3,_)->
2618-
if v1=1usthen
2619-
warning(Error(FSComp.SR.buildRequiresCLI2(filename),rangeStartup))
2618+
| Some(v1,v2,_,_)->
26202619
letclrRoot= Some(Path.GetDirectoryName(FileSystem.GetFullPathShim(filename)))
2621-
2622-
clrRoot,(int v1, sprintf"v%d.%d" v1 v2),(v1=5us&& v2=0us&& v3=5us)// SL5 mscorlib is 5.0.5.0
2620+
clrRoot,(sprintf"v%d.%d" v1 v2)
26232621
|_->
26242622
failwith(FSComp.SR.buildCouldNotReadVersionInfoFromMscorlib())
26252623
with e->
@@ -2628,48 +2626,15 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
26282626
#if!ENABLE_MONO_SUPPORT
26292627
// TODO: we have to get msbuild out of this
26302628
if data.useSimpleResolutionthen
2631-
None,(0,""),false
2629+
None,""
26322630
else
26332631
#endif
2634-
None,(4,data.legacyReferenceResolver.HighestInstalledNetFrameworkVersion()),false
2632+
None, data.legacyReferenceResolver.HighestInstalledNetFrameworkVersion()
26352633

2636-
// Note: anycpu32bitpreferred can only be used with .Net version 4.5 and above
2637-
// but now there is no way to discriminate between 4.0 and 4.5,
2638-
// so here we minimally validate if .Net version >= 4 or not.
2639-
doif data.prefer32Bit&& mscorlibMajorVersion<4then
2640-
error(Error(FSComp.SR.invalidPlatformTargetForOldFramework(),rangeCmdArgs))
2641-
26422634
letsystemAssemblies= SystemAssemblies()
26432635

2644-
// Check that the referenced version of FSharp.Core.dll matches the referenced version of mscorlib.dll
2645-
letcheckFSharpBinaryCompatWithMscorlib filename(ilAssemblyRefs:ILAssemblyRef list)explicitFscoreVersionToCheckOpt m=
2646-
letisfslib= fileNameOfPath filename= GetFSharpCoreLibraryName()+".dll"
2647-
match ilAssemblyRefs|> List.tryFind(fun aref-> aref.Name= data.primaryAssembly.Name)with
2648-
| Some aref->
2649-
match aref.Versionwith
2650-
| Some(v1,_,_,_)->
2651-
if isfslib&&((v1<4us)<>(mscorlibMajorVersion<4))then
2652-
// the versions mismatch, however they are allowed to mismatch in one case:
2653-
if primaryAssemblyIsSilverlight&& mscorlibMajorVersion=5// SL5
2654-
&&(match explicitFscoreVersionToCheckOptwith
2655-
| Some(2us,3us,5us,_)// silverlight is supported for FSharp.Core 2.3.5.x and 3.47.x.y
2656-
| Some(3us,47us,_,_)
2657-
| None->true// the 'None' code path happens after explicit FSCore was already checked, from now on SL5 path is always excepted
2658-
|_->false)
2659-
then
2660-
()
2661-
else
2662-
error(Error(FSComp.SR.buildMscorLibAndFSharpCoreMismatch(filename),m))
2663-
// If you're building an assembly that references another assembly built for a more recent
2664-
// framework version, we want to raise a warning
2665-
elifnot(isfslib)&&((v1=4us)&&(mscorlibMajorVersion<4))then
2666-
warning(Error(FSComp.SR.buildMscorlibAndReferencedAssemblyMismatch(filename),m))
2667-
else
2668-
()
2669-
|_->()
2670-
|_->()
2671-
26722636
// Look for an explicit reference to FSharp.Core and use that to compute fsharpBinariesDir
2637+
// FUTURE: remove this, we only read the binary for the exception it raises
26732638
letfsharpBinariesDirValue=
26742639
#if FX_NO_SIMPLIFIED_LOADER
26752640
data.defaultFSharpBinariesDir
@@ -2680,7 +2645,7 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
26802645
if fslibReference.ProjectReference.IsNonethen
26812646
try
26822647
use ilReader= OpenILBinary(filename,data.optimizeForMemory,data.openBinariesInMemory,None,None, data.shadowCopyReferences)
2683-
checkFSharpBinaryCompatWithMscorlib filename ilReader.ILAssemblyRefs ilReader.ILModuleDef.ManifestOfAssembly.Version rangeStartup;
2648+
()
26842649
with e->
26852650
error(Error(FSComp.SR.buildErrorOpeningBinaryFile(filename, e.Message), rangeStartup))
26862651

@@ -2690,7 +2655,6 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
26902655
data.defaultFSharpBinariesDir
26912656
#endif
26922657

2693-
memberx.MscorlibMajorVersion= mscorlibMajorVersion
26942658
memberx.primaryAssembly= data.primaryAssembly
26952659
memberx.autoResolveOpenDirectivesToDlls= data.autoResolveOpenDirectivesToDlls
26962660
memberx.noFeedback= data.noFeedback
@@ -3020,10 +2984,6 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
30202984
membertcConfig.ResolveSourceFile(m,nm,pathLoadedFrom)=
30212985
data.ResolveSourceFile(m, nm, pathLoadedFrom)
30222986

3023-
membertcConfig.CheckFSharpBinary(filename,ilAssemblyRefs,m)=
3024-
use unwindBuildPhase= PushThreadBuildPhaseUntilUnwind BuildPhase.Parameter
3025-
checkFSharpBinaryCompatWithMscorlib filename ilAssemblyRefs None m
3026-
30272987
// NOTE!! if mode=Speculative then this method must not report ANY warnings or errors through 'warning' or 'error'. Instead
30282988
// it must return warnings and errors as data
30292989
//
@@ -4165,7 +4125,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
41654125
if providerAssemblies.Count>0then
41664126

41674127
// Find the SystemRuntimeAssemblyVersion value to report in the TypeProviderConfig.
4168-
letsystemRuntimeAssemblyVersion=
4128+
letprimaryAssemblyVersion=
41694129
letprimaryAssemblyRef= tcConfig.PrimaryAssemblyDllReference()
41704130
letresolution= tcConfig.ResolveLibWithDirectories(CcuLoadFailureAction.RaiseError, primaryAssemblyRef)|> Option.get
41714131
// MSDN: this method causes the file to be opened and closed, but the assembly is not added to this domain
@@ -4192,7 +4152,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
41924152
letproviders=
41934153
[for assemblyNamein providerAssembliesdo
41944154
yield ExtensionTyping.GetTypeProvidersOfAssembly(fileNameOfRuntimeAssembly, ilScopeRefOfRuntimeAssembly, assemblyName, typeProviderEnvironment,
4195-
tcConfig.isInvalidationSupported, tcConfig.isInteractive, systemRuntimeContainsType,systemRuntimeAssemblyVersion, m)]
4155+
tcConfig.isInvalidationSupported, tcConfig.isInteractive, systemRuntimeContainsType,primaryAssemblyVersion, m)]
41964156
letproviders= providers|> List.concat
41974157

41984158
// Note, type providers are disposable objects. The TcImports owns the provider objects - when/if it is disposed, the providers are disposed.
@@ -4273,7 +4233,6 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
42734233
membertcImports.PrepareToImportReferencedILAssembly(ctok,m,filename,dllinfo:ImportedBinary)=
42744234
CheckDisposed()
42754235
lettcConfig= tcConfigP.Get(ctok)
4276-
tcConfig.CheckFSharpBinary(filename,dllinfo.ILAssemblyRefs,m)
42774236
assert dllinfo.RawMetadata.TryGetRawILModule().IsSome
42784237
letilModule= dllinfo.RawMetadata.TryGetRawILModule().Value
42794238
letilScopeRef= dllinfo.ILScopeRef
@@ -4310,9 +4269,9 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
43104269

43114270
membertcImports.PrepareToImportReferencedFSharpAssembly(ctok,m,filename,dllinfo:ImportedBinary)=
43124271
CheckDisposed()
4272+
#if EXTENSIONTYPING
43134273
lettcConfig= tcConfigP.Get(ctok)
4314-
tcConfig.CheckFSharpBinary(filename, dllinfo.ILAssemblyRefs, m)
4315-
4274+
#endif
43164275
letilModule= dllinfo.RawMetadata
43174276
letilScopeRef= dllinfo.ILScopeRef
43184277
letilShortAssemName= getNameOfScopeRef ilScopeRef
@@ -4636,7 +4595,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
46364595
// OK, now we have both mscorlib.dll and FSharp.Core.dll we can create TcGlobals
46374596
lettcGlobals= TcGlobals(tcConfig.compilingFslib,ilGlobals,fslibCcu,
46384597
tcConfig.implicitIncludeDir,tcConfig.mlCompatibility,
4639-
tcConfig.isInteractive,tryFindSysTypeCcu, tcConfig.emitDebugInfoInQuotations,(tcConfig.primaryAssembly.Name="mscorlib"),tcConfig.noDebugData)
4598+
tcConfig.isInteractive,tryFindSysTypeCcu, tcConfig.emitDebugInfoInQuotations, tcConfig.noDebugData)
46404599

46414600
#if DEBUG
46424601
// the global_g reference cell is used only for debug printing

‎src/fsharp/CompileOptions.fs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,12 @@ let cliRootFlag (_tcConfigB : TcConfigBuilder) =
746746
letSetTargetProfile tcConfigB v=
747747
tcConfigB.primaryAssembly<-
748748
match vwith
749+
// Indicates we assume "mscorlib.dll", i.e .NET Framework, Mono and Profile 47
749750
|"mscorlib"-> PrimaryAssembly.Mscorlib
750-
|"netcore"-> PrimaryAssembly.DotNetCore
751+
// Indicates we assume "System.Runtime.dll", i.e .NET Standard 1.x, .NET Core App 1.x and above, and Profile 7/78/259
752+
|"netcore"-> PrimaryAssembly.System_Runtime
753+
// Indicates we assume "netstandard.dll", i.e .NET Standard 2.0 and above
754+
|"netstandard"-> PrimaryAssembly.NetStandard
751755
|_-> error(Error(FSComp.SR.optsInvalidTargetProfile(v), rangeCmdArgs))
752756

753757
letadvancedFlagsBoth tcConfigB=

‎src/fsharp/FSComp.txt‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ buildProductNameCommunity,"F# Compiler for F# %s"
4444
213,buildInvalidAssemblyName,"'%s' is not a valid assembly name"
4545
214,buildInvalidPrivacy,"Unrecognized privacy setting '%s' for managed resource, valid options are 'public' and 'private'"
4646
215,buildMultipleReferencesNotAllowed,"Multiple references to '%s.dll' are not permitted"
47-
216,buildRequiresCLI2,"The file '%s' is a CLI 1.x version of mscorlib. F# requires CLI version 2.0 or greater."
4847
buildCouldNotReadVersionInfoFromMscorlib,"Could not read version from mscorlib.dll"
49-
217,buildMscorlibAndReferencedAssemblyMismatch,"The referenced or default base CLI library 'mscorlib' is binary-incompatible with the referenced library '%s'. Consider recompiling the library or making an explicit reference to a version of this library that matches the CLI version you are using."
5048
218,buildCannotReadAssembly,"Unable to read assembly '%s'"
51-
219,buildMscorLibAndFSharpCoreMismatch,"The referenced or default base CLI library 'mscorlib' is binary-incompatible with the referenced F# core library '%s'. Consider recompiling the library or making an explicit reference to a version of this library that matches the CLI version you are using."
5249
220,buildAssemblyResolutionFailed,"Assembly resolution failure at or near this location"
5350
221,buildImplicitModuleIsNotLegalIdentifier,"The declarations in this file will be placed in an implicit module '%s' based on the file name '%s'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file."
5451
222,buildMultiFileRequiresNamespaceOrModule,"Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. 'namespace SomeNamespace.SubNamespace' or 'module SomeNamespace.SomeModule'. Only the last source file of an application may omit such a declaration."
@@ -906,12 +903,12 @@ optsDCLOHtmlDoc,"The command-line option '%s' has been deprecated. HTML document
906903
optsConsoleColors,"Output warning and error messages in color"
907904
optsUseHighEntropyVA,"Enable high-entropy ASLR"
908905
optsSubSystemVersion,"Specify subsystem version of this assembly"
909-
optsTargetProfile,"Specify target framework profile of this assembly. Valid values are mscorlibornetcore. Default - mscorlib"
906+
optsTargetProfile,"Specify target framework profile of this assembly. Valid values are mscorlib, netcoreornetstandard. Default - mscorlib"
910907
optsEmitDebugInfoInQuotations,"Emit debug information in quotations"
911908
optsPreferredUiLang," Specify the preferred output language culture name (e.g. es-ES, ja-JP)"
912909
optsNoCopyFsharpCore,"Don't copy FSharp.Core.dll along the produced binaries"
913910
1051,optsInvalidSubSystemVersion,"Invalid version '%s' for '--subsystemversion'. The version must be 4.00 or greater."
914-
1052,optsInvalidTargetProfile,"Invalid value '%s' for '--targetprofile', valid values are 'mscorlib'or 'netcore'."
911+
1052,optsInvalidTargetProfile,"Invalid value '%s' for '--targetprofile', valid values are 'mscorlib', 'netcore'or 'netstandard'."
915912
typeInfoFullName,"Full name"
916913
# typeInfoType,"type"
917914
# typeInfoInherits,"inherits"
@@ -1275,7 +1272,6 @@ typeInfoCallsWord,"Calls"
12751272
3151,tcThisValueMayNotBeInlined,"This member, function or value declaration may not be declared 'inline'"
12761273
3152,etErasedTypeUsedInGeneration,"The provider '%s' returned a non-generated type '%s' in the context of a set of generated types. Consider adjusting the type provider to only return generated types."
12771274
3153,tcUnrecognizedQueryBinaryOperator,"Arguments to query operators may require parentheses, e.g. 'where (x > y)' or 'groupBy (x.Length / 10)'"
1278-
3154,invalidPlatformTargetForOldFramework,"The 'anycpu32bitpreferred' platform flag may only be used with .NET Framework versions 4.5 and greater."
12791275
3155,crefNoSetOfHole,"A quotation may not involve an assignment to or taking the address of a captured local variable"
12801276
nicePrintOtherOverloads1,"+ 1 overload"
12811277
nicePrintOtherOverloadsN,"+ %d overloads"

‎src/fsharp/FSharp.Build/Microsoft.FSharp.NetSdk.targets‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
3535
<_ExplicitReferenceInclude="$(FrameworkPathOverride)\mscorlib.dll"Condition=" '$(NoStdLib)' != 'true'" />
3636
</ItemGroup>
3737

38+
<PropertyGroup>
39+
<_TargetFrameworkVersionWithoutV>$(TargetFrameworkVersion)</_TargetFrameworkVersionWithoutV>
40+
<_TargetFrameworkVersionWithoutVCondition="$(TargetFrameworkVersion.StartsWith('v'))">$(TargetFrameworkVersion.Substring(1))</_TargetFrameworkVersionWithoutV>
41+
</PropertyGroup>
42+
3843
<PropertyGroup>
3944
<TargetProfileCondition=" '$(TargetFrameworkIdentifier)' == '.NETFramework'" >mscorlib</TargetProfile>
4045
<TargetProfileCondition=" '$(TargetFrameworkIdentifier)' != '.NETFramework'" >netcore</TargetProfile>
46+
<TargetProfileCondition=" '$(TargetFrameworkIdentifier)' == '.NETStandard' and '$(_TargetFrameworkVersionWithoutV)' >= '2.0'" >netstandard</TargetProfile>
4147
<OtherFlags>$(OtherFlags) --simpleresolution --nocopyfsharpcore</OtherFlags>
4248
</PropertyGroup>
4349

@@ -52,8 +58,14 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
5258
</PropertyGroup>
5359

5460
<PropertyGroupCondition=" '$(DisableImplicitSystemValueTupleReference)' != 'true'">
55-
<_FrameworkNeedsValueTupleReferenceCondition=" $(TargetFramework.StartsWith(netcoreapp1.)) or $(TargetFramework.StartsWith(netstandard1.))">true</_FrameworkNeedsValueTupleReference>
56-
<_FrameworkNeedsValueTupleReferenceCondition=" '$(TargetFramework)' == 'net40' or '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'net46' or '$(TargetFramework)' == 'net461' or '$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'net47'">true</_FrameworkNeedsValueTupleReference>
61+
<_FrameworkNeedsValueTupleReferenceCondition=" ('$(TargetFrameworkIdentifier)' == '.NETStandard' or '$(TargetFrameworkIdentifier)' == '.NETCoreApp') and !('$(_TargetFrameworkVersionWithoutV)' >= '2.0')">true</_FrameworkNeedsValueTupleReference>
62+
<_FrameworkNeedsValueTupleReferenceCondition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' and
63+
('$(_TargetFrameworkVersionWithoutV)' == '4.0' or
64+
'$(_TargetFrameworkVersionWithoutV)' == '4.5' or
65+
'$(_TargetFrameworkVersionWithoutV)' == '4.6' or
66+
'$(_TargetFrameworkVersionWithoutV)' == '4.6.1' or
67+
'$(_TargetFrameworkVersionWithoutV)' == '4.6.2' or
68+
'$(_TargetFrameworkVersionWithoutV)' == '4.7')">true</_FrameworkNeedsValueTupleReference>
5769
</PropertyGroup>
5870

5971
<ItemGroup>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp