Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d2layout-dagre: Compile fully statically with musl libc #31

Closed
nhooyr opened this issue Oct 31, 2022 · 14 comments
Closed

d2layout-dagre: Compile fully statically with musl libc #31

nhooyr opened this issue Oct 31, 2022 · 14 comments

Comments

@nhooyr
Copy link
Contributor

nhooyr commented Oct 31, 2022

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

@nhooyr nhooyr added this to D2 Oct 31, 2022
@nhooyr nhooyr moved this to Todo in D2 Oct 31, 2022
@nhooyr nhooyr removed the status in D2 Oct 31, 2022
@nhooyr
Copy link
Contributor Author

nhooyr commented Nov 11, 2022

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

@nhooyr
Copy link
Contributor Author

nhooyr commented Nov 11, 2022

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
Copy link
Contributor Author

nhooyr commented Nov 13, 2022

Relevant: rogchap/v8go#170

@nhooyr
Copy link
Contributor Author

nhooyr commented Nov 23, 2022

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!

@Vaelatern
Copy link
Contributor

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?

@nhooyr
Copy link
Contributor Author

nhooyr commented Nov 24, 2022

d2 imports d2plugin-dagre by default. But the d2 command itself is pure Go. You can use --tags nodagre to build without dagre. See

//go:build cgo && !nodagre

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

@alixander
Copy link
Collaborator

rogchap/v8go#350

@nhooyr
Copy link
Contributor Author

nhooyr commented Nov 30, 2022

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

@alixander
Copy link
Collaborator

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.

@nhooyr
Copy link
Contributor Author

nhooyr commented Dec 3, 2022

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

@nhooyr
Copy link
Contributor Author

nhooyr commented Dec 3, 2022

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

@nhooyr
Copy link
Contributor Author

nhooyr commented Dec 3, 2022

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

@nhooyr
Copy link
Contributor Author

nhooyr commented Dec 3, 2022

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 nhooyr mentioned this issue Dec 3, 2022
@alixander
Copy link
Collaborator

we can close this now that goja's worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants