d2 icon indicating copy to clipboard operation
d2 copied to clipboard

d2layout-dagre: Compile fully statically with musl libc

Open nhooyr opened this issue 3 years ago • 6 comments

See https://honnef.co/posts/2015/06/statically_compiled_go_programs__always__even_with_cgo__using_musl/

nhooyr avatar Oct 31 '22 03:10 nhooyr

Another possible approach is to compile with qemu. I believe this is how code-server now handles cross compilation.

nhooyr avatar Nov 11 '22 06:11 nhooyr

On nvm, qemu would help us avoid needing to maintain a builder of each architecture and OS but we'd still need one of each OS at the least. I don't think there's any easy way to cross compile for a different platform apart from using zig which I'll need to research further.

nhooyr avatar Nov 11 '22 07:11 nhooyr

Relevant: https://github.com/rogchap/v8go/issues/170

nhooyr avatar Nov 13 '22 05:11 nhooyr

https://xeiaso.net/blog/carcinization-golang

we could also compile v8 to wasm and execute in a pure go wasm runtime instead. then no cgo at all!

nhooyr avatar Nov 23 '22 06:11 nhooyr

This currently fully breaks build on musl, including of the d2 command itself (not just d2plugin-dagre).

Is there no easy way to cut this out and require e.g. a library to be present on the system, or something else like that?

Vaelatern avatar Nov 24 '22 02:11 Vaelatern

d2 imports d2plugin-dagre by default. But the d2 command itself is pure Go. You can use --tags nodagre to build without dagre. See https://github.com/terrastruct/d2/blob/f64ed4981e911ef54d0b9ff6c204fc4c591b06fd/d2plugin/plugin_dagre.go#L1

or CGO_ENABLED=0 go build ...

The only pure Go layout engine we currently have is TALA which requires a license. See https://github.com/terrastruct/tala

nhooyr avatar Nov 24 '22 08:11 nhooyr

https://github.com/rogchap/v8go/pull/350

alixander avatar Nov 30 '22 21:11 alixander

@alixander damn nice how did you know that someone opened a PR fixing it?

nhooyr avatar Nov 30 '22 23:11 nhooyr

i brieflyz considering calling React from Go for server side renders (probably won't go with that), and the potential extra reliance on v8go made me investigate its activity.

alixander avatar Nov 30 '22 23:11 alixander

Can also try https://github.com/dop251/goja?

nhooyr avatar Dec 03 '22 08:12 nhooyr

Also means it will be far easier to do #136 when there's no cgo involved.

nhooyr avatar Dec 03 '22 08:12 nhooyr

Ok maybe not far given the dagre/elk javascript can just run in the browser lol.

nhooyr avatar Dec 03 '22 08:12 nhooyr

omg what if we just embedded the node binary? code-server used to do this thing where they embedded the node binary/js into a single binary. they probably still do. we could do it too.

nhooyr avatar Dec 03 '22 08:12 nhooyr

we can close this now that goja's worked.

alixander avatar Dec 03 '22 23:12 alixander