-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Compile fsx #1728
[WIP] Compile fsx #1728
Conversation
About the limitation to references #if !FAKE
#r "Facades/netstandard"
#r "netstandard"
#endif |
@MangelMaxime yeah tried that, it doesn't load all the necessary references that way. |
In fable-compiler-js we're injecting the necessary references by ourselves, so maybe we could do the same here. The main need for Msbuild is to load other files properly instead of just using regex (for example, if My main concern about scripts is it's currently more cumbersome to add references to packages than generating an SDK-style fsproj. |
Hi @alfonsogarciacaro, could you elaborate a bit more, please?
|
Yes 😸
Also yep. Anything that requires paths to external folders in your local machine becomes problematic when shared in a repo. And the only way I know to use packages with an .fsx is to use Paket with the generate_fsx_scripts options, which requires some setup and kind-of defeats the purpose of using an .fsx to test things quickly. |
@nojaf what's the limitation you see in this issue and |
@enricosada I think the |
You can choose the version, but only .NET full is considered. There isn’t an FSI for .net core yet, that’s why i didn’t support that |
The main ux problem here is probably when you want to For all other deps, paket would be the only usable option atm. Maybe that can improve in #5850. |
Discovered fable-metadata today! It also solves the problem of getting intellisense when using vanilla Fable. #r "./node_modules/fable-metadata/lib/Fable.Core.dll"
open Fable.Core |
@nojaf Just keep in mind those binaries in fable-metadata don't contain code, just metadata. |
@ncave I believe that is all I need, do you see any harm in this approach @alfonsogarciacaro? |
@nojaf Well, the main issue is fable-compiler package doesn't have a dependency to fable-metadata so it's not safe to assume the dlls will actually be there. Maybe you can use some basic types to detect the location of the assemblies:
|
dd1aeb3
to
027307b
Compare
@alfonsogarciacaro @enricosada I stole like a lot of code from |
Sorry @nojaf, I missed the notification. What's the difference between Dotnet.ProjInfo and Dotnet.ProjInfo.Workspace.FCS? |
FsxBinder is used to get the projectoptions from the script. |
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<RuntimeFrameworkVersion>2.1.0</RuntimeFrameworkVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="../fable-standalone/src/Metadata.fs" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a similar list to Metadata.references_core in Fable.Cli/Util.fs (SYSTEM_CORE_REFERENCES), maybe we could unify them somehow.
// TEMP NOJAF | ||
module Utils = | ||
|
||
let runProcess (log: string -> unit) (workingDir: string) (exePath: string) (args: string) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a similar helper to this in Fable.Cli/Util.fs (Process.start).
if not (String.IsNullOrEmpty ev) then [ev] | ||
else EnvUtils.tryFindPath (sideBySidePaths @ legacyPaths) "MsBuild.exe" | ||
|
||
type MSBuildLocator () = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should only call MBuild through dotnet SDK (dotnet msbuild). If we want to allow non-global dotnet
locations we should parameterize it, because it's also used in other locations (when calling dotnet restore
, when the dotnet process is spawned from node...).
static member FromPATH (msbuildLocator: MSBuildLocator) = | ||
{ NetFWInfoConfig.MSBuildHost = msbuildLocator.MSBuildFromPATH } | ||
|
||
module internal NETFrameworkInfoProvider = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't worry about different NET Framework versions, we can just assume netstandard2.0 which is what Fable supports.
yield "System.Web.Services" | ||
yield "System.Windows.Forms" | ||
yield "System.Numerics" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have this list but also a reference to Metadata.references_core. Why are both needed?
// END TEMP | ||
|
||
let getProjectOptionsFromScript scriptFile = | ||
let (checker: FSharpChecker) = FSharpChecker.Create(keepAssemblyContents=true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This checker won't be used to read the AST so we shouldn't need keepAssemblyContents
. Also, there seems to be a high bootstrap time to initialize a checker, I hope it's not the case here.
let tfm = netFwInfo.LatestVersion () // or specify a .NET version like `"4.6.1"` | ||
let fsxBinder = FsxBinder(netFwInfo, checker) | ||
|
||
let input = System.IO.File.ReadAllText(scriptFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files should be read in non-blocking fashion to prevent issues. See
Lines 13 to 17 in d7dc236
/// File.ReadAllText fails with locked files. See https://stackoverflow.com/a/1389172 | |
let readAllText path = | |
use fileStream = new IO.FileStream(path, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.ReadWrite) | |
use textReader = new IO.StreamReader(fileStream) | |
textReader.ReadToEnd() |
dllPath::dllRs | ||
else | ||
dllRs | ||
) dllRx Fable.Standalone.Metadata.references_core |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're adding here the basic System assemblies necessary to compile Fable projects, what's the rest of the code doing, just getting custom #r
references and file #load
s?
Also, Metadata.references_core
only includes assembly names not their location in the machine. How is this solved.
TBH, I'm a bit reluctant to add a dependency without knowing well what it does. The README in enricosada/dotnet-proj-info doesn't mention the Dotnet.ProjInfo.Workspace packages and the name seems to suggest they are related to the Workspace functionality in VS Code which doesn't have anything to do with Fable 🤔 |
Sorry for late reply. @alfonsogarciacaro the I have a PR open in FSAC ( ionide/FsAutoComplete#347 ) to replace all the code to navigate project/get fsc arguments/etc, using that library instead. In fable will eventually replace this code https://github.com/fable-compiler/Fable/blob/e965930ec30937ccc8d9613684a3fc98ad491196/src/Fable.Cli/ProjectCoreCracker.fs with one or two lines (same feature, but maintained in a library with fixes, and some more like choose NOTE i am dogfooding the library in FSAC atm, it's not ready yet that's why is not publicly announced yet. i have one or two bugs more to fix. |
Thanks for explanations @enricosada. That's very good to hear, I'd be very happy to remove the ProjectCoreCracker file because right now I wouldn't know how to edit it in case of need. A couple of notes about the current Fable situation if you want to send a PR :)
|
Final will be like this, that's why already exists
Np, is transparent for the library. if you want to use modern fsproj (best obv), is ok.
There is no file changes watcher. When will be added in a later version, will be optional and built on top of base functions. Thank for the info @alfonsogarciacaro better be sure will be ok to integrate, when ready! |
13a9f4e
to
dbf433a
Compare
Closing in favor of #1780 |
Using Dotnet.ProjInfo.Workspace.FCS we can compile fsx files as well.
Possible flow
Users use paket for dependencies.
paket load
can create a script to reference everything needed.#load @".paket\load\netstandard2.0\main.group.fsx"
Current limitations
script.fsx:
#r @"C:\Users\nojaf\.nuget\packages\netstandard.library\2.0.3\build\netstandard2.0\ref\netstandard.dll"
Todo