JuliaIO / ProtoBuf.jl

Julia protobuf implementation
Other
205 stars 55 forks source link

Path requirements for importing .proto files conflicts with grpc #254

Closed wilf-phasecraft closed 2 months ago

wilf-phasecraft commented 2 months ago

I have several .proto under the following directory structure

- mylibrary
|-- foo.proto
|-- bar.proto

The bar.proto file imports foo.proto using

import "mylibrary/foo.proto";

And this works fine when using gRPC to build Python code. However, when using ProtoBuf.jl as follows, I get a LoadError

import ProtoBuf

src = "."
dest = "../julia"

paths = ["foo.proto", "bar.proto"]

mkpath(dest)
ProtoBuf.protojl(paths, src, dest)
julia> include("generate_julia.jl")
ERROR: LoadError: Could not find following imports: ["mylibrary/numeric.proto"] within ["/Users/wilfrid/Documents/Projects/proto-buffet/mylibrary/", "/Users/wilfrid/.julia/packages/ProtoBuf/uNPdY/src/"]

It works fine if I simply specify the import as

import "foo.proto";

But then the gRPC fails to build the Python code. Am I missing something here?

wilf-phasecraft commented 2 months ago
ERROR: LoadError: Could not find following imports: ["phasecraft/numeric.proto"] within ["/Users/wilfrid/Documents/Projects/proto-buffet/phasecraft/", "/Users/wilfrid/.julia/packages/ProtoBuf/uNPdY/src/"]
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] resolve_imports!(imported_paths::Set{String}, parsed_files::Dict{String, ProtoBuf.CodeGenerators.ResolvedProtoFile}, search_directories::Vector{String})
   @ ProtoBuf.CodeGenerators ~/.julia/packages/ProtoBuf/uNPdY/src/codegen/modules.jl:255
 [3] _protojl(relative_paths::Vector{String}, search_directories::String, output_directory::String, options::ProtoBuf.CodeGenerators.Options)
   @ ProtoBuf.CodeGenerators ~/.julia/packages/ProtoBuf/uNPdY/src/codegen/CodeGenerators.jl:166
 [4] #protojl#36
   @ ~/.julia/packages/ProtoBuf/uNPdY/src/codegen/CodeGenerators.jl:138 [inlined]
 [5] protojl(relative_paths::Vector{String}, search_directories::String, output_directory::String)
   @ ProtoBuf.CodeGenerators ~/.julia/packages/ProtoBuf/uNPdY/src/codegen/CodeGenerators.jl:126
 [6] top-level scope
   @ ~/Documents/Projects/proto-buffet/mylibrary/generate_julia.jl:10
 [7] include(fname::String)
   @ Base.MainInclude ./client.jl:489
 [8] top-level scope
   @ REPL[2]:1
in expression starting at /Users/wilfrid/Documents/Projects/proto-buffet/mylibrary/generate_julia.jl:10
wilf-phasecraft commented 2 months ago

Fixed by simply adding the parent to the search directories

import ProtoBuf

src = [".", ".."]
dest = "../julia"

paths = ["foo.proto", "bar.proto"]

mkpath(dest)
ProtoBuf.protojl(paths, src, dest)