xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.04k stars 786 forks source link

Setting proto_public=true removes protobuf gens directory from compile_commands.json #2256

Closed madhurajith closed 2 years ago

madhurajith commented 2 years ago

Xmake Version

2.6.4

Operating System Version and Architecture

Ubuntu

Describe Bug

If proto_public=true is set for protobuf.cpp rule, then the source files in the same target lose the protobuf gens folder from the compile_commands.json args,

e.g. The compile command, /usr/bin/ccache /usr/bin/gcc -c -m64 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -Iinclude -Ibuild/.gens/proto_lib/linux/x86_64/release/rules/protobuf/proto -isystem /home/user/.xmake/packages/p/protobuf-cpp/3.19.4/b2115fa005c149c3a814138eccc0044e/include -DNDEBUG -o build/.objs/proto_lib/linux/x86_64/release/src/lib.cpp.o src/lib.cpp

Corresponding compile_commands.json entry,

{
  "directory": "/home/user/proto_lib",
  "arguments": ["/usr/bin/ccache", "/usr/bin/gcc", "-c", "-m64", "-Iinclude", "-I", "/home/namal/.xmake/packages/p/protobuf-cpp/3.19.4/b2115fa005c149c3a814138eccc0044e/include", "-o", "build/.objs/proto_lib/linux/x86_64/release/src/lib.cpp.o", "src/lib.cpp"],
  "file": "src/lib.cpp"
}

The .gens folder is lost only from the compilation units of the same target. The target that consumes the library still get the correct include path.

Expected Behavior

Protobuf gens folder should always be in the same target arguments in the compile_commands.json.

Project Configuration

To reproduce,

  1. Uncomment the protobuf.cpp rule with proto_public=ture
  2. xmake clean
  3. xmake build
  4. From inside VSCode run "XMake: UpdateIntellisense"

To see the correct behaviour, switch the protobuf.cpp rule without proto_public=true and do the same steps and check the compile_commands.json file.

Switching from one config to the other and generating the compile_commands.json is bit in-deterministic. Please repeat the process several times if you don't see the issue in the first try.

proto_lib.zip

Additional Information and Error Logs

No response

waruqi commented 2 years ago

you can update to dev and add add_rules("protobuf.cpp")

xmake update -s dev

madhurajith commented 2 years ago

Switched to dev branch but I can still see the issue.

It's quite strange now. Running XMake: UpdateIntellisense from vscode multiple times leads to different outputs. Sometimes protobuf include path is there. Other times it is not there. Some in-deterministic stuff going on.

waruqi commented 2 years ago

It works for me. I cannot reproduce it

you can run xmake project -k compile_commands to test it.

madhurajith commented 2 years ago

Issue is still there. I'll make a video to show what is happening.

madhurajith commented 2 years ago

Attached video shows what I get when i run xmake project -k compile_commands multiple times in my ubuntu machine,

Run Time lib.cpp has protobuf include main.cpp has protobuf include
1 5s Yes No
2 10s No Yes
3 15s No No
4 20s No Yes
5 25s Yes No
6 30s Yes Yes

This is an unedited video. No tricks. Exact behaviour I get.

In this case I'm using add_files("proto/*.proto", {rules="protobuf.cpp", proto_public=true}) therefore I expect the output in run 6 to be the output in each run

https://user-images.githubusercontent.com/27882764/163656668-3cfb1598-fcf1-46d3-94ef-dec03bd65725.mp4

waruqi commented 2 years ago

please add add_rules("protobuf.cpp")

madhurajith commented 2 years ago

That fixed the issue of protobuf gens folder missing out.

However there is a duplicate entry for test.pb.cc

add_rules("mode.debug", "mode.release")

add_requires("protobuf-cpp")

target("proto_lib")
    set_kind("static")
    add_installfiles("include/lib.hpp")
    add_includedirs("include", {public=true})
    add_files("src/lib.cpp")
    add_files("proto/*.proto", {rules="protobuf.cpp", proto_public=true})
    --add_files("proto/*.proto", {rules="protobuf.cpp"})
    add_packages("protobuf-cpp")
    add_rules("protobuf.cpp")

target("proto_lib_test")
    set_kind("binary")
    add_files("src/main.cpp")
    add_deps("proto_lib")
[
{
  "directory": "/home/namal/Temp/proto_lib",
  "arguments": ["/usr/bin/ccache", "/usr/bin/gcc", "-c", "-m64", "-g", "-O0", "-Iinclude", "-Ibuild/.gens/proto_lib/linux/x86_64/debug/rules/protobuf/proto", "-o", "build/.objs/proto_lib_test/linux/x86_64/debug/src/main.cpp.o", "src/main.cpp"],
  "file": "src/main.cpp"
},
{
  "directory": "/home/namal/Temp/proto_lib",
  "arguments": ["/usr/bin/ccache", "/usr/bin/gcc", "-c", "-m64", "-g", "-O0", "-Iinclude", "-I", "/home/namal/.xmake/packages/p/protobuf-cpp/3.19.4/b2115fa005c149c3a814138eccc0044e/include", "-std=c++11", "-Ibuild/.gens/proto_lib/linux/x86_64/debug/rules/protobuf/proto", "-o", "build/.objs/proto_lib/linux/x86_64/debug/gens/rules/protobuf/proto/test.pb.cc.o", "build/.gens/proto_lib/linux/x86_64/debug/rules/protobuf/proto/test.pb.cc"],
  "file": "build/.gens/proto_lib/linux/x86_64/debug/rules/protobuf/proto/test.pb.cc"
},
{
  "directory": "/home/namal/Temp/proto_lib",
  "arguments": ["/usr/bin/ccache", "/usr/bin/gcc", "-c", "-m64", "-g", "-O0", "-Iinclude", "-I", "/home/namal/.xmake/packages/p/protobuf-cpp/3.19.4/b2115fa005c149c3a814138eccc0044e/include", "-std=c++11", "-Ibuild/.gens/proto_lib/linux/x86_64/debug/rules/protobuf/proto", "-o", "build/.objs/proto_lib/linux/x86_64/debug/gens/rules/protobuf/proto/test.pb.cc.o", "build/.gens/proto_lib/linux/x86_64/debug/rules/protobuf/proto/test.pb.cc"],
  "file": "build/.gens/proto_lib/linux/x86_64/debug/rules/protobuf/proto/test.pb.cc"
},
{
  "directory": "/home/namal/Temp/proto_lib",
  "arguments": ["/usr/bin/ccache", "/usr/bin/gcc", "-c", "-m64", "-g", "-O0", "-Iinclude", "-Ibuild/.gens/proto_lib/linux/x86_64/debug/rules/protobuf/proto", "-I", "/home/namal/.xmake/packages/p/protobuf-cpp/3.19.4/b2115fa005c149c3a814138eccc0044e/include", "-o", "build/.objs/proto_lib/linux/x86_64/debug/src/lib.cpp.o", "src/lib.cpp"],
  "file": "src/lib.cpp"
}]
waruqi commented 2 years ago
add_files("proto/*.proto", {rules="protobuf.cpp", proto_public=true})

remove rules

add_files("proto/*.proto", {proto_public=true})
madhurajith commented 2 years ago

That fixed the issue. Thanks