protojure/protoc-plugin

Golang fork behavior problem

reify-tanner-stirrat opened this issue · 7 comments

Description

I'm trying to use the buf project to build a protobuf client that's hosted with their system. When I use protoc-gen-clojure as the target plugin, the command fails with:

Failure: plugin clojure: fork/exec /Users/me/.local/bin/protoc-gen-clojure: exec format error

This doesn't seem to be specific to buf, but rather to the packaging of the plugin:

package main

import (
	"fmt"
	"os/exec"
)

func main() {
	fmt.Println(exec.Command("protoc-gen-clojure").Run())
}

produces the same error.

This happens with both the prebuilt 2.1.0 release and with a locally built binary based on most recent master.

Is there anything about jars that makes them incompatible with a fork call? If not, what would need to change to make this compatible with go tooling? It'd be nice to be able to use this plugin with buf.

You may already know this, but the protojure plugin uses lein-bin to make an "executable jar" but really what that means is it's a jar file with a shell-script preamble. I'm guessing that the exec method is running afoul of whatever that shell script preamble requires to work properly. FWIW, you can also just run it with 'java -jar path/to/plugin', so perhaps there is some kind of wrapper you could devise to make it happy in the context of the buf executor?

I didn't know that, so thank you for the context!

I think that the Go approach to running the binary isn't actually shelling out, where I'm guessing protoc must. I'll relay that back to the buf maintainers and see if there's a path forward. For my purposes, I have a workaround (namely pulling the relevant .proto files from the project I'm interested in), but I'd be excited to see a build process that is compatible with more tooling.

I hacked around a bit, and it seems that prepending a #!/bin/sh line is all that's necessary for Go to be happy with it. Is that something that could be added to the tooling, or is that something that would break things for someone else?

I'd have to look into it, but I suspect the issue would be that lein-bin generates a preamble that will work with both Unix and windows shells, and I suspect that approach would break it. I honestly don't know if any protojure users use windows, but I would hesitate to break it.

Does it sound like a wrapper shell may be a work-around for you for now?

Yeah, it's definitely a workaround for me right now. Would you be open to documenting this somewhere? If so, is there a place that you'd prefer me to put the documentation?

A PR is definitely welcome. I don't have an opinion on the best place, so make a proposal and we can discuss if I have any kind of objection, but that's doubtful

I added a PR for that 👍