Code Monkey home page Code Monkey logo

fsx's Introduction

FSX

PUBLIC SERVICE ANNOUNCEMENT

THIS REPO IS FACING A COMPLETE OVERHAUL/REVAMP/RENOVATION IN ORDER TO SUPPORT .NET6.

Unfinished tasks so far:

Motivation

FSX is the ideal tool for people that use F# for their scripting needs.

The best way to describe it is to start first with some questions:

  • Have you found yourself waiting many seconds until your big script is parsed by FSI and run? This is unacceptable when doing many small changes and expecting a quick feedback loop to test them.
  • Do you have long-running F# scripts that cause too much memory usage in your server?
  • Have you found that your scripts could bitrot over time (i.e. not compile anymore) especially when using helper functions in .fs files loaded by them?

These are the main annoyances when working with F# scripting. Granted, F#+FSI is already much better than the alternatives (as many more errors are thrown much earlier than at runtime, and as strongly-typed functional languages are generally faster). However, we can do better.

To the above three questions we could even follow-up with new ones:

  • Couldn't we make FSI only compile what's changed, and reuse binaries from a previous run, to speed this up?
  • Couldn't we run our script without FSI given that FSI eats a lot of memory (for REPL features, which scripts don't need)?
  • Couldn't we have a CI approach that takes care of our scripts in a similar way as we do with (msbuild-ed) C#/F# code?

FSX answers all of these latter questions with a categorical YES!

The creation of FSX was inspired by several facts:

  • FSI is slower than the F# compiler (obviously).
  • There should be an easy and programatic way to compile an F# script without trying to run it (see https://stackoverflow.com/questions/33468298/f-how-can-i-compile-and-then-release-a-file-fsx ).
  • FSI (or the components required to run it) suffers from bugs frequently. Examples:
    • If your version of Mono is too old (e.g. 4.6.2, the version that comes by default in Ubuntu 18.04), then it might crash with a segmentation fault. More info: https://bugzilla.xamarin.com/show_bug.cgi?id=42417 .
    • If your version of Mono is not too old, but your version of F# is not too new (e.g. what happens exactly with Ubuntu 19.04), then FSI might not work at all. More info: fsharp/fsharp#740 .
  • FSI stands for F Sharp Interactive, which means that it's not really suited for scripting but more for debugging:
    • It doesn't treat warnings as errors by default (you would need to remember to use the flag --warnaserror when calling fsharpi, which is not handy).
    • Because of the previous point above about warnings, it can even cancel the advantage of the promise of "statically-compiled scripts" altogether, because what should be a compilation error could be translated to a runtime error when using currified arguments, due to FSI defaulting to "interactive" needs. (More info: https://stackoverflow.com/questions/38202685/fsx-script-ignoring-a-function-call-when-i-add-a-parameter-to-it )
    • AFAIK there's no way to use flags in a shebang (so can't use #!/usr/bin/env fsharpi --warnaserror as the flag gets ignored). Note that using fsx in shebang, however, will treat warnings as errors.
    • It can consume a lot of memory, just compare it this way:
echo $'#!/usr/bin/env fsharpi\nSystem.Threading.Thread.Sleep(999999999)'>testfsi.fsx
echo $'#!/usr/bin/env fsx\nSystem.Threading.Thread.Sleep(999999999)'>testfsx.fsx
chmod u+x test*.fsx
nohup ./testfsi.fsx >/dev/null 2>&1 &
nohup ./testfsx.fsx >/dev/null 2>&1 &
ps aux | grep testfs

In my machine, the above prints:

andres   23596 16.6  0.9 254504 148268 pts/24  Sl   03:38   0:01 cli /usr/lib/cli/fsharp/fsi.exe --exename:fsharpi ./testfsi.fsx
andres   23600  0.0  0.0 129332 15936 pts/24   Sl   03:38   0:00 mono bin/./testfsx.fsx.exe

Which is a huge difference in memory footprint.

How to install/use?

Installation

In Linux/macOS, the old-fashioned way by cloning and compiling it yourself:

./configure.sh --prefix=/usr/local
make
sudo make install

(If you're using Windows, just build with "make.bat" and install with "make install".)

Usage

Execution

After installing, you can already use the #!/usr/bin/env fsx shebang in your scripts.

If you want to use fsx without having to change the shebang of all your scripts, just run fsx yourscript.fsx every time.

Compilation

For your CI needs (to compile all scripts in your repo without executing them), you could call fsxc using find in your CI step.

An example of how to do this with GitHub Actions, is this YML fragment that you could add to your workflow existing in your .github/workflows/ folder:

    - name: compile F# scripts
      shell: bash
      run: |
        dotnet new tool-manifest
        dotnet tool install fsxc
        find . -type f -name "*.fsx" | xargs -t -I {} dotnet fsxc {}

fsx's People

Contributors

aarani avatar bobface avatar knocte avatar msonawane avatar tehraninasab avatar webwarrior-ws avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fsx's Issues

Warnings are ignored in .NET6

If you place a test.fsx with a warning (in a place where there is no Directory.Build.props, and your current directory doesn't have this file either), e.g.:

let GiveMeBool():bool = false
GiveMeBool()
printf "hello"

This seems to not fail in .NET6:

"%programfiles%\fsx\fsxc.exe" -f test.fsx

While it seems it would fail in .NET4.x, judging by --warnaserror present in these lines 777,778 in Fsxc.fs:

                (sprintf
                    "%s %s %s --warnaserror --target:exe --out:%s %s"

fsx -k would run the script

The -k flag was meant to be only for fsxc (not fsx) program, but we're showing it in the fsx case, and in that case it's not doing what it says (it should just compile and not run).

Create gitlab-ci pipeline that generates snap package

Deliverables:

  1. An MR/PR that adds a pipeline to gitlab-ci.yml file that creates a snap package.
  2. Snap package must be exposed as an artifact.

Requirements:

  1. Snap package must be compatible with Ubuntu 18.04 and 19.04.
  2. (Optional-bonus-points) snap package can work even if mono and fsharp deb packages are not installed? (this might be much harder to achieve, I'll give a big tip if done)

Deprecate fsx altogether?

In the F# discord channel today I learned about the --typecheck-only flag of the compiler, let's investigate it.

fsx -f doesn't work (in Windows?)

C:\Users\knocte\Documents\Code>"%programfiles%\fsx\fsx.bat" -f test.fsx

C:\Users\knocte\Documents\Code>"%programfiles%\fsx\fsx.bat" test.fsx
hello

Sync version.config file with AssemblyInfo.fs with bump.fsx

  • Take in account AssemblyInfo.fs is not included in Fsdk.fsproj (it is in Fsdk-legacy.fsproj), by mistake.
  • Ideally bump.fsx should also create the git tag (and advice to push it, like in geewallet).
  • nugetPush of git tag should verify that tag starts with BaseVersion val of version.config.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.