Skip to content
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

TargetFramework for Fable #2338

Closed
wallymathieu opened this issue Jan 2, 2021 · 13 comments
Closed

TargetFramework for Fable #2338

wallymathieu opened this issue Jan 2, 2021 · 13 comments

Comments

@wallymathieu
Copy link

wallymathieu commented Jan 2, 2021

Description

In order to specify dependencies that only makes sense when compiling an F# project against Fable it would make sense to have a separate TargetFramework intended for use with Fable.

Repro code

The repro code would be some library code that works on both .net and Fable but requires some additional Fable specific JavaScript to work (say timer and async logic).

An example would be Fuchu where the async code could have slightly different implementation. For Fuchu it wouldn't make sense to try to take on a dependency on Fuchu for netstandard2.0, but it would make sense to take it on for fuchu3 for instance.

Related information

  • Fable version: 3
  • Operating system
@alfonsogarciacaro
Copy link
Member

I think there was a similar discussion somewhere but I cannot find it now. Is it possible to define custom target frameworks? I thought only the ones defined by the dotnet sdk were allowed: netstandard, netcoreapp, net5.0, etc.

@wallymathieu
Copy link
Author

I think there are other target frameworks besides those. It's probably related to some NuGet/ msbuild logic.

@alfonsogarciacaro
Copy link
Member

It would be better not to mess around with MSBuild, like requiring users to import some props file. Also, Fable already depends on simplistic XML parsing of the .fsproj files in some situations, and we are already seeing weird dependency bugs like #2326. What do you have in mind to create a custom target framework for Fable?

@wallymathieu
Copy link
Author

Yes, I wonder what's required in order to make it not weird like that. You might be able to package it as a NuGet.

@inosik
Copy link
Contributor

inosik commented Jan 7, 2021

Samsung uses a custom target framework for Tizen projects, so it's possible. Their custom MSBuild SDK adds implicit package references, some targets and enables some VS tooling, depending on that.

It looks like the .NET SDK v5 knows about the Tizen runtime, which is based on Linux, according to dotnet/sdk/5.0.101/RuntimeIdentifierGraph.json. I'm not sure about the framework, though. If it has to be "blessed" by Microsoft or anything.

@wallymathieu
Copy link
Author

That's neat, so it might be possible then to do something similar for Fable 😃

@alfonsogarciacaro
Copy link
Member

Well, the "custom MSBuild SDK" part doesn't sound like an easy feat though ;)

@wallymathieu
Copy link
Author

Depends on how much help we can get from people that are familiar with MsBuild. I'm thinking that if you have a minimal targetframework definition (without involving the actual Fable compiler to start with) it might be feasible.

@ncave
Copy link
Collaborator

ncave commented Jan 8, 2021

@wallymathieu The project parsing in Fable is entirely done by the Dotnet.ProjInfo component, so perhaps this issue can be raised there too, to see if custom framework targets can be properly supported.

If what you're looking for is just a conditionally different set of assembly dependencies, perhaps a much less-involving solution would be to have a way to add/remove/replace dependencies through the command line, after project parsing.

Finally, for completeness, it's worth mentioning that the fable-compiler-js doesn't use MSBuild (or even .NET) at all and it parses the project file directly, so technically anything is possible there. Although it's probably not a good idea to try to re-implement a complex piece of machinery that is MSBuild in its entirety.

@wallymathieu
Copy link
Author

I'm thinking also about how to package existing libs to be compatible with Fable. We probably wan't to add custom implementations around async: fsprojects/FSharpPlus#419 that also depends on Fable libraries for the Fable implementation. It would not make sense to take on a Fable dependency for all targetframeworks.

@wallymathieu
Copy link
Author

I've done some experiments and got this: fable-targetframework-test-main.zip though that's not good enough.

@MangelMaxime
Copy link
Member

Just because it hasn't been mentioned in this issue yet.

The solution used in general to provide a Fable version of a library or a .Net version of a library right now is simply to publish 2 packages.

For example:

  • Fable.Elmish and `Elmish
  • Thoth.Json and Thoth.Json.Net

If needed, the user or library maintainer can use FABLE_COMPILER compiler directive to "fork" the code depending on the runtime used.
I know that the discussion here was to have a single package and allow to have different dependencies as done for libraries targeting netstandard2 and net467 for example.

Just wanted to re-mention this because sometimes the simple solution is enough.

As @ncave said, fable-compiler-js doesn't use MSBUILD so it already seems that not only we will need to understand MSBUILD but also probably have a separate implementation (even if simple) for that version of Fable...

@alfonsogarciacaro
Copy link
Member

Closing for now as dealing with msbuild is not on the roadmap atm, please reopen if someone is willing to give it a try or there's another question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants