roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.16k stars 293 forks source link

Build shared libraries on `roc run ...`, `roc dev ...`, and `roc ...` #5399

Open bhansconnect opened 1 year ago

bhansconnect commented 1 year ago

dependent on #5398 so that it can work with packaged platforms.

These commands do not need create an output binary. Only roc build needs to do that. In order to get really fast linking for all of these, generate a shared library (to start just using system linker) to a tmp dir. Then run the raw host file with the newly generated shared library (we may need to standardize how the host is setup to link with the app or update the link file path).

This will enable practically instant linking on all platforms.

The eventual goal is to remove the system linker dependency. Instead, we would generate the shared libraries from scratch. This should not be that hard given the only dependency is the platform. It also should make this path always faster than the current surgical linker. The surgical linker would then only be used with roc build where an output executable is wanted.

As a note, in my testing, using the system linker tends to take about 40-60ms (way better than the 1-2s of the legacy linker). The surgical linker on the other hand varies based on the platform size. From my testing was between 15ms and 150ms (and generally towards the low end).

bhansconnect commented 1 year ago

Extra note, when updating this, we will need to change platforms to link with -rdynamic otherwise they won't properly expose symbols to the shared library.