nblockchain / fsx

FSX is the ideal tool for people that use F# for their scripting needs.
MIT License
14 stars 5 forks source link

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:

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:

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

The creation of FSX was inspired by several facts:

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 {}