Skip to content

Commit

Permalink
use specialized protoc invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmaykm committed Feb 22, 2024
1 parent 44c839c commit fbfdfbf
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/generate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ function get_generated_method_table(s::String)
T
end

# Defining a local protoc to avoid issues with ProtoBuf.protoc,
# wherein it was using the form `protoc_jll.protoc() do .. end`
# which is now deprecated and is causing errors in code generation.
function grpc_protoc(args=``)
plugin_dir = abspath(joinpath(dirname(pathof(ProtoBuf)), "..", "plugin"))
plugin = joinpath(plugin_dir, Sys.iswindows() ? "protoc-gen-julia_win.bat" : "protoc-gen-julia")

protoc_path = ProtoBuf.protoc_jll.protoc()
ENV= copy(ENV)
ENV′["PATH"] = string(plugin_dir, Sys.iswindows() ? ";" : ":", ENV′["PATH"])
ENV′["JULIA"] = joinpath(Sys.BINDIR, Base.julia_exename())
run(setenv(`$protoc_path --plugin=protoc-gen-julia=$plugin $args`, ENV′))
end

"""
generate(proto::String; outdir::String=pwd())
Expand Down Expand Up @@ -149,7 +163,7 @@ function generate(proto::String; outdir::String=pwd(), includes::Vector{String}=
bindir = Sys.BINDIR
pathenv = string(ENV["PATH"], Sys.iswindows() ? ";" : ":", bindir)
withenv("PATH"=>pathenv) do
ProtoBuf.protoc(`$includeflag --julia_out=$outdir $proto`)
grpc_protoc(`$includeflag --julia_out=$outdir $proto`)
end

# include the generated code and detect service method names
Expand Down

0 comments on commit fbfdfbf

Please sign in to comment.