koka-lang / koka

Koka language compiler and interpreter
http://koka-lang.org
Other
3.28k stars 163 forks source link

Consider using existing shared libs? #205

Open SchrodingerZhu opened 3 years ago

SchrodingerZhu commented 3 years ago

The PCRE examples indicate that Koka seems to scan for static libs (especially for those from vcpkg) on default. Is it possible to consider build the lib with shared lib support if it is feasible in the given environment?

For example,


{
  cdylib = "pcre-2.8",
  linker-flags = [ "-rpath" ] 
}
daanx commented 3 years ago

Yes, at the moment only static linking is supported; There is still work to be done to make even static linking better (and I hope it gets improved once I integrate libuv). For now, you can specify in an extern import:

It would be nice to have Conan & pcconfig support as well for now I am holding back a bit as I guess what Koka really needs is a package manager. The goal is though to be opinionated and have koka builds be seamless where external libraries get build/found automatically.

I am very hesitant about dynamic linking as that has many issues on many platforms and makes deterministic builds difficult. Given the limited resources, for now, I would like to pursue a static linking approach only for Koka but make it as easy as possible. A nice benefit is that a Koka binary will only depend on libc and can be run without dynamic link failures at deployment.

iacore commented 2 years ago

Here because of this error when compiling.

warning: unable to find C library: pcre2-8
   hint: provide "--cclibdir" as an option, or use "syslib" in an extern import?
failure during code generation:
  unable to find C library pcre2-8
  library search paths: ["/usr/local/lib","/usr/lib","/lib"]

Is it possible to bundle pcre source code with koka?

About static linking, does koka use musl libc? Even most "static" libraries depend on external libc symbols. Even the hello world application in Koka depends on GNU libc.

I recommend using https://github.com/ziglang/zig/ as the C compiler and build system for Koka, since it can handle cross-compilation and link with musl by itself.

Let's discuss static linking here: https://github.com/koka-lang/koka/discussions/254