A question that came up in a discussion this morni...
# present-company
k
A question that came up in a discussion this morning: Suppose you want to publish a command-line utility program, meant to be easy to use. Doing Web retrieval and some post-processing. Around 500 lines in a typical scripting language, but with dependencies (in that language plus C libraries). It looks like packaging such a tool for all popular platforms (i.e. package managers) will be a lot more work than actually writing the code. True? Any way to avoid this? Ideas so far: don't use a scripting language, but something with a compiler that can produce portable executables for every major platform. Recommendations in that category so far: Go, Rust, Racket, Common Lisp. I have doubts that all of these can handle "plus C libraries", but it's a start. Does anyone here have actual experience with this kind of project?
a
Do you just want a package, or do you wanted it listed in all the registries for installation by name?
b
It's relatively new, but if you're open to experimenting, take a look at https://pkgx.sh/
j
I can’t actually evaluate whether it’s a good idea, but https://justine.lol/ape.html exists
c
I think runnable fat .jar is probably the best bet, like the Apache Tika standalone app. It has about a million dependencies under the hood but the user experience is just to download a single executable that runs on all platforms (that have java)
t
@Konrad Hinsen did you consider Pharo+C?
k
@Tudor Girba Briefly. I have never seen a command-line tool written in Pharo in the wild, so I can only speculate how that would be distributed. For plain Pharo code, I imagine a tarball containing the VM and the image, plus a script that takes care of running the VM with the right parameters to find the image. The obstacle I see is the C dependencies. For macOS and Windows, I could add the binaries to the tarball. For Linux, there is too much heterogeneity to distribute binaries, so I'd have to find a way to make the Pharo code find the libraries wherever the system package manager has put them. And that's something that only the package manager knows for sure. Scientific computing environments are particularly challenging because "Linux" really means "anything with a Linux kernel". There's high-performance computing centres running prehistoric CentOS versions ("we prefer known bugs to unknown bugs"), nerd laptops with the latest exotic distribution, and in between more standard installations such as Debian or Ubuntu, in any versions from ten years ago to bleeding edge.
There are a thousand things to optimize over in this question, but this is one way.
k
That looks nice, thanks! It doesn't mention C dependencies though...
j
There’s FFI, but you still have the problem of whether the libs you want to use are installed. The maximally safe case is to static link everything into a platform specific binary using, zB
go
.
a
Cosmopolitan C is surprisingly powerful!
k
@Jack Rusher It's either that, or integration of my code into whatever build system the target platform uses. Both options require a lot of overhead effort. @Arcade Wise Found it (https://justine.lol/cosmopolitan/) - that's amazing! Not sure I'd be willing to write my code in C in order to use it, but it's pretty cool :-)
a
Yeah! It’s wild. I wonder how hard it would be to make a language that compiles to and has bindings for cosmo C
k
Not so much a language but a toolchain, right? Any language that can be compiled to C should be adaptable rather easily. That includes C++, Fortran, Scheme, Common Lisp, and probably many others.
m
Node with WebAseembly? https://nodejs.dev/en/learn/nodejs-with-webassembly/ I don't have direct experience with WASM in Node, but many platforms can run Node.
k
But is it possible to create stand-alone binaries? If users have to install node, installation is too complicated.
m
Looks like there's experimental work, but yeah I wouldn't depend on that yet. https://nodejs.org/api/single-executable-applications.html. There is however, pkg: https://medium.com/@tech_girl/deploy-your-node-js-application-as-a-single-executable-4103a2508dd7 I may experiment with this myself, it looks interesting. The binary will be fairly large of course, since it's the whole JavaScript VM + your app 🙂