rongfengliang / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Mono support for ProtoGen #144

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

First attempt:
1. Build ProtoGen under Mono (I built on Linux, using `xbuild` in the ProtoGen 
directory)
2. Run ProtoGen on a .proto file (I used the first example from 
http://code.google.com/apis/protocolbuffers/docs/overview.html): mono 
protogen.exe -i:example.proto
  Output:
    protobuf-net:protogen - code generator for .proto
    ApplicationName='/tmp/ff3e50edfc0e4a07aef7a39bf81e22f5/protoc.exe', CommandLine='"--descriptor_set_out=/tmp/tmp87c88f4.tmp" "--proto_path=/home/whitelynx/devel/protobuf-net-v1/ProtoGen" "--proto_path=/tmp/ff3e50edfc0e4a07aef7a39bf81e22f5" --error_format=gcc "/home/whitelynx/devel/protobuf-net-v1/ProtoGen/example.proto" ', CurrentDirectory='/home/whitelynx/devel/protobuf-net-v1/ProtoGen'

As near as I can tell, it's trying to run protoc.exe but failing, since it's a 
Windows executable.

Second attempt:
1. Remove old build.
2. Edit ProtoGen.csproj and modify this line:
    <EmbeddedResource Include="..\Tools\protoc.exe">
  to look like:
    <EmbeddedResource Include="\usr\bin\protoc">
3. Rebuild ProtoGen
4. Run ProtoGen on a .proto file: mono protogen.exe -i:example.proto
  Output:
    protobuf-net:protogen - code generator for .proto
    Object reference not set to an instance of an object

What version of the product are you using? On what operating system?
  OS: Arch Linux
  protobuf-net: v1 branch, revision 358
  protobuf: 2.3.0
  mono: 2.8.1

Email: whitelynx -at- gmail

Original issue reported on code.google.com by whitel...@gmail.com on 1 Dec 2010 at 9:04

GoogleCodeExporter commented 9 years ago

Original comment by marc.gravell on 2 Feb 2011 at 8:15

GoogleCodeExporter commented 9 years ago
Is there any more assistance I can provide with troubleshooting this? I'd 
submit a patch if I had an idea of which direction to go with it...

Original comment by whitel...@gmail.com on 15 Feb 2011 at 3:23

GoogleCodeExporter commented 9 years ago
The problem is that it tries to execute the embedded "protoc" (unmanaged 
executable).

That is available for *nix, so it *should* just be a case of swapping that out. 
Incidentally, you can use protoc *in isolation* to compile to binary, and then 
give this to protogen, in which case it won't need to run protoc.

Original comment by marc.gravell on 15 Feb 2011 at 3:42

GoogleCodeExporter commented 9 years ago
I had tried just swapping it out in my second attempt above, but it ended up 
getting a null reference exception when I ran it.

Could you provide an example of using protoc separately with protogen? I hadn't 
seen a way to do that, but it'd be a great workaround until protogen gets fixed 
for Mono.

Original comment by whitel...@gmail.com on 15 Feb 2011 at 4:31

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Ok, I found a way to run protoc and protogen together... thought I had found a 
way to run them without a temporary file, but it appears that neither of them 
recognizes '-' as stdin/stdout, so piping protoc's output to protogen doesn't 
work.

Here's the workaround I'm using now:

  protoc -I. kCL.proto -okCL.bin
  protogen -i:kCL.bin -o:kCL.cs

Original comment by whitel...@gmail.com on 15 Feb 2011 at 4:38

GoogleCodeExporter commented 9 years ago
That is a nice workaround. I'll see of I can think of an elegant way of doig 
this more generally without needing to embed both binaries

Original comment by marc.gravell on 15 Feb 2011 at 5:44

GoogleCodeExporter commented 9 years ago
Also - I'll check the stdin issue; iirc I support stdout - kinda surprised I 
don't handle stdin

Original comment by marc.gravell on 15 Feb 2011 at 5:46

GoogleCodeExporter commented 9 years ago
You may want to look at protoc's new plugin support; see 
http://code.google.com/apis/protocolbuffers/docs/reference/other.html and 
http://www.mail-archive.com/protobuf@googlegroups.com/msg03764.html .

Original comment by whitel...@gmail.com on 15 Feb 2011 at 6:00

GoogleCodeExporter commented 9 years ago
Also, I wrote up a quick, generic Makefile using that workaround; I've attached 
it in case anyone else finds it useful in the meantime. If you'd like to use 
it, make sure to at least adjust the path to protogen.exe at the top of the 
file.

Original comment by whitel...@gmail.com on 15 Feb 2011 at 6:27

Attachments:

GoogleCodeExporter commented 9 years ago
I was able to fix the issue on Ubuntu by just adding a symbolic link:

  ubuntu@ubuntu-VirtualBox:/usr/bin$ sudo ln -s protoc protoc.exe

That allowed 'mono ProtoGen.exe' to find the unmanaged executable even though 
it's using the .exe extension.

Original comment by mark.der...@gmail.com on 15 Mar 2014 at 9:17

GoogleCodeExporter commented 9 years ago
Sorry-- I forgot to say that I had to delete the Windows binary from the 
Protobuf-CSharp-Port/tools directory so that it would not be found first.

Original comment by mark.der...@gmail.com on 15 Mar 2014 at 9:20