8000 `"rust-analyzer.cargo.features": "all"` equivalent · Issue #13600 · microsoft/vscode-cpptools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

"rust-analyzer.cargo.features": "all" equivalent #13600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
loynoir opened this issue May 10, 2025 · 0 comments
Open

"rust-analyzer.cargo.features": "all" equivalent #13600

loynoir opened this issue May 10, 2025 · 0 comments

Comments

@loynoir
Copy link
loynoir commented May 10, 2025

Feature Request

actual

Given compile_commands.json use same lib.c with ALL below three status in order

  • without define, is lib mode, output library

  • define test, is test mode, output binary

  • define bench, is bench mode, output binary

Actually, vscode show lib.c

  • lib region code is not gray

  • test region code is gray!

  • bench region code is gray!

compile_commands.json
[
 {
   "directory": "/tmp/repo/build/example/example_add_u64",
   "command": "/usr/lib/ccache/bin/cc  -I/tmp/repo/src/example/example_add_u64/include  -o CMakeFiles/example_add_u64__lib.dir/src/lib.c.o -c /tmp/repo/src/example/example_add_u64/src/lib.c",
   "file": "/tmp/repo/src/example/example_add_u64/src/lib.c",
   "output": "example/example_add_u64/CMakeFiles/example_add_u64__lib.dir/src/lib.c.o"
 },
 {
   "directory": "/tmp/repo/build/example/example_add_u64",
   "command": "/usr/lib/ccache/bin/cc -Dtest -I/tmp/repo/src/example/example_add_u64/include  -o CMakeFiles/example_add_u64__lib_test.dir/src/lib.c.o -c /tmp/repo/src/example/example_add_u64/src/lib.c",
   "file": "/tmp/repo/src/example/example_add_u64/src/lib.c",
   "output": "example/example_add_u64/CMakeFiles/example_add_u64__lib_test.dir/src/lib.c.o"
 },
 {
   "directory": "/tmp/repo/build/example/example_add_u64",
   "command": "/usr/lib/ccache/bin/cc -Dbench -I/tmp/repo/src/example/example_add_u64/include  -o CMakeFiles/example_add_u64__lib_bench.dir/src/lib.c.o -c /tmp/repo/src/example/example_add_u64/src/lib.c",
   "file": "/tmp/repo/src/example/example_add_u64/src/lib.c",
   "output": "example/example_add_u64/CMakeFiles/example_add_u64__lib_bench.dir/src/lib.c.o"
 }
]
lib.c
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

uint64_t add_u64(uint64_t left, uint64_t right) {
  uint64_t ret = left + right;

  return ret;
}

// TODO: gray
#ifdef test
#define TEST_MAIN(F)                                                           \
  int main(int argc, char *argv[]) {                                           \
    (void)argc;                                                                \
    (void)argv;                                                                \
    F();                                                                       \
    return EXIT_SUCCESS;                                                       \
  }

void it_works() {
  uint64_t result = add_u64(2, 2);
  if (result != 4) {
    exit(EXIT_FAILURE);
  }
}

TEST_MAIN(it_works)
#endif

// TODO: gray
#ifdef bench
#define BENCH_MAIN(F)                                                          \
  int main(int argc, char *argv[]) {                                           \
    (void)argc;                                                                \
    (void)argv;                                                                \
    F();                                                                       \
    return EXIT_SUCCESS;                                                       \
  }

void it_works() {
  uint64_t result = add_u64(2, 2);
  if (result != 4) {
    exit(EXIT_FAILURE);
  }
}

BENCH_MAIN(it_works)
#endif

workaround

Workaround

  • compile_commands.json remove lib mode element

vscode show lib.c

  • lib region code is not gray

  • test region code is not gray

  • bench region code is gray

compile_commands.json
[
  {
    "directory": "/tmp/repo/build/example/example_add_u64",
    "command": "/usr/lib/ccache/bin/cc -Dtest -I/tmp/repo/src/example/example_add_u64/include  -o CMakeFiles/example_add_u64__lib_test.dir/src/lib.c.o -c /tmp/repo/src/example/example_add_u64/src/lib.c",
    "file": "/tmp/repo/src/example/example_add_u64/src/lib.c",
    "output": "example/example_add_u64/CMakeFiles/example_add_u64__lib_test.dir/src/lib.c.o"
  },
  {
    "directory": "/tmp/repo/build/example/example_add_u64",
    "command": "/usr/lib/ccache/bin/cc -Dbench -I/tmp/repo/src/example/example_add_u64/include  -o CMakeFiles/example_add_u64__lib_bench.dir/src/lib.c.o -c /tmp/repo/src/example/example_add_u64/src/lib.c",
    "file": "/tmp/repo/src/example/example_add_u64/src/lib.c",
    "output": "example/example_add_u64/CMakeFiles/example_add_u64__lib_bench.dir/src/lib.c.o"
  }
]
lib.c
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

uint64_t add_u64(uint64_t left, uint64_t right) {
  uint64_t ret = left + right;

  return ret;
}

#ifdef test
#define TEST_MAIN(F)                                                           \
  int main(int argc, char *argv[]) {                                           \
    (void)argc;                                                                \
    (void)argv;                                                                \
    F();                                                                       \
    return EXIT_SUCCESS;                                                       \
  }

void it_works() {
  uint64_t result = add_u64(2, 2);
  if (result != 4) {
    exit(EXIT_FAILURE);
  }
}

TEST_MAIN(it_works)
#endif

// TODO: gray
#ifdef bench
#define BENCH_MAIN(F)                                                          \
  int main(int argc, char *argv[]) {                                           \
    (void)argc;                                                                \
    (void)argv;                                                                \
    F();                                                                       \
    return EXIT_SUCCESS;                                                       \
  }

void it_works() {
  uint64_t result = add_u64(2, 2);
  if (result != 4) {
    exit(EXIT_FAILURE);
  }
}

BENCH_MAIN(it_works)
#endif

related

rust cargo features should be C define equivalent.

cargo have an auto enabled feature named default.

Inspired by

  "rust-analyzer.cargo.features": "all",

feat

I suggest

When

  • "C_Cpp.default.compileCommandsDefinesAll": false

UI behavior as same as current

When

  • "C_Cpp.default.compileCommandsDefinesAll": true

Given compile_commands.json use same lib.c with ALL below three status in order

  • without define, is lib mode, output library

  • define test, is test mode, output binary

  • define bench, is bench mode, output binary

Expect vscode show lib.c

  • lib region code is not gray

  • test region code is not gray

  • bench region code is not gray

@loynoir loynoir changed the title rust-analyzer.cargo.features equivalent "rust-analyzer.cargo.features": "all" equivalent May 10, 2025
@loynoir loynoir changed the title "rust-analyzer.cargo.features": "all" equivalent "rust-analyzer.cargo.features": "all" equivalent May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants
0