Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: add .clang-format #120

Merged
merged 2 commits into from
Apr 6, 2025
Merged

Conversation

saurabhraghuvanshii
Copy link
Contributor

@saurabhraghuvanshii saurabhraghuvanshii commented Feb 24, 2025

fixes #104

  • Add .clang-format for format file with some set rule
  • And To keep consistent format
  • refer some pre built style file ( WebKit , LLVM, Microsoft)

Test

  • test locally it work on file by running command clang-format -i <filename>

Next step

  • for automation on CI , falling if code is not formatted
  • And documentation in CONTRIBUTING.md

@jandubois
Copy link
Member

jandubois commented Feb 24, 2025

@saurabhraghuvanshii Can you please update your commits to include a DCO (see https://github.com/lima-vm/socket_vmnet/pull/120/checks?check_run_id=37732521320 for more details)

@nirs Can you do a review of the .clang-format file to see if that is what we want?

@saurabhraghuvanshii
Copy link
Contributor Author

I will sir update my commit for now my wifi is not working and my mobile data is not sufficient.

@saurabhraghuvanshii
Copy link
Contributor Author

Okay sir, I will update I am thinking of asking this. But for clear i create new file. Thanks sir

Copy link
Member

@nirs nirs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll review more later, added some comments for now.

@saurabhraghuvanshii saurabhraghuvanshii force-pushed the Clang-format branch 2 times, most recently from aa5a225 to e991931 Compare February 25, 2025 15:31
@jandubois jandubois requested a review from nirs March 9, 2025 06:36
Copy link
Member

@nirs nirs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks simple now, but there is no reason to split to several commits. Please squash the commit to one commit.

@nirs
Copy link
Member

nirs commented Apr 2, 2025

Lets try to do this work smaller steps:

  1. Create a .clang-format file that keep the code mostly unchanged when formatting it.
  2. Modify the code so it matches the clang-format file
  3. Add a clang-format job that format all code and fail if the diff is not empty.

@nirs
Copy link
Member

nirs commented Apr 2, 2025

If we use LLVM style the code needs only minor changes:

$ cat .clang-format 
---
Language: Cpp
BasedOnStyle:  LLVM
---

$ clang-format -i *.c *.h client/*.c

$ git diff --stat                   
 cli.c  | 30 ++++++++++++++++--------------
 log.h  | 12 ++++++------
 main.c | 56 ++++++++++++++++++++++++++++----------------------------
 3 files changed, 50 insertions(+), 48 deletions(-)

The diff is much smaller and include simple modifications that makes sense. The following are example changes from the diff.

This is uglier - but it is easier to work with the code if we don't need to format it manually:

   const struct option longopts[] = {
-    {"socket-group",        required_argument,  NULL,   CLI_OPT_SOCKET_GROUP},
-    {"vmnet-mode",          required_argument,  NULL,   CLI_OPT_VMNET_MODE},
-    {"vmnet-interface",     required_argument,  NULL,   CLI_OPT_VMNET_INTERFACE},
-    {"vmnet-gateway",       required_argument,  NULL,   CLI_OPT_VMNET_GATEWAY},
-    {"vmnet-dhcp-end",      required_argument,  NULL,   CLI_OPT_VMNET_DHCP_END},
-    {"vmnet-mask",          required_argument,  NULL,   CLI_OPT_VMNET_MASK},
-    {"vmnet-interface-id",  required_argument,  NULL,   CLI_OPT_VMNET_INTERFACE_ID},
-    {"vmnet-nat66-prefix",  required_argument,  NULL,   CLI_OPT_VMNET_NAT66_PREFIX},
-    {"pidfile",             required_argument,  NULL,   'p'},
-    {"help",                no_argument,        NULL,   'h'},
-    {"version",             no_argument,        NULL,   'v'},
-    {0, 0, 0, 0},
+      {"socket-group", required_argument, NULL, CLI_OPT_SOCKET_GROUP},
+      {"vmnet-mode", required_argument, NULL, CLI_OPT_VMNET_MODE},
+      {"vmnet-interface", required_argument, NULL, CLI_OPT_VMNET_INTERFACE},
+      {"vmnet-gateway", required_argument, NULL, CLI_OPT_VMNET_GATEWAY},
+      {"vmnet-dhcp-end", required_argument, NULL, CLI_OPT_VMNET_DHCP_END},
+      {"vmnet-mask", required_argument, NULL, CLI_OPT_VMNET_MASK},
+      {"vmnet-interface-id", required_argument, NULL,
+       CLI_OPT_VMNET_INTERFACE_ID},
+      {"vmnet-nat66-prefix", required_argument, NULL,
+       CLI_OPT_VMNET_NAT66_PREFIX},
+      {"pidfile", required_argument, NULL, 'p'},
+      {"help", no_argument, NULL, 'h'},
+      {"version", no_argument, NULL, 'v'},
+      {0, 0, 0, 0},
   };
   int opt = 0;
   while ((opt = getopt_long(argc, argv, "hvp:", longopts, NULL)) != -1) {

Aligning to starting "(" looks good, we can add a commit with these changes.

@@ -196,7 +198,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
   if (res->vmnet_gateway == NULL) {
     if (res->vmnet_mode != VMNET_BRIDGED_MODE) {
       WARN("--vmnet-gateway=IP should be explicitly specified to "
-          "avoid conflicting with other applications");
+           "avoid conflicting with other applications");
     }
     if (res->vmnet_dhcp_end != NULL) {
       ERROR("--vmnet-dhcp-end=IP requires --vmnet-gateway=IP");

Again the aligned version looks better, but it is easier to maintain the clang-format style:

-#define INFOF(fmt, ...)     fprintf(stderr, "INFO | " fmt "\n", __VA_ARGS__)
-#define ERROR(msg)          fprintf(stderr, "ERROR| " msg "\n")
-#define ERRORF(fmt, ...)    fprintf(stderr, "ERROR| " fmt "\n", __VA_ARGS__)
-#define ERRORN(name)        ERRORF(name ": %s", strerror(errno))
-#define WARN(msg)           fprintf(stderr, "WARN | " msg "\n")
-#define WARNF(fmt, ...)     fprintf(stderr, "WARN | " fmt "\n", __VA_ARGS__)
+#define INFOF(fmt, ...) fprintf(stderr, "INFO | " fmt "\n", __VA_ARGS__)
+#define ERROR(msg) fprintf(stderr, "ERROR| " msg "\n")
+#define ERRORF(fmt, ...) fprintf(stderr, "ERROR| " fmt "\n", __VA_ARGS__)
+#define ERRORN(name) ERRORF(name ": %s", strerror(errno))
+#define WARN(msg) fprintf(stderr, "WARN | " msg "\n")
+#define WARNF(fmt, ...) fprintf(stderr, "WARN | " fmt "\n", __VA_ARGS__)

This is clearly better, we can add a commit adding these changes:

 #endif /* SOCKET_VMNET_LOG_H */
diff --git a/main.c b/main.c
index a2e87de..2752eec 100644
--- a/main.c
+++ b/main.c
@@ -110,7 +110,7 @@ static void state_remove_socket_fd(struct state *state, int socket_fd) {
       for (conn = state->conns; conn->next != NULL; conn = conn->next) {
         if (conn->next->socket_fd == socket_fd) {
           conn->next = conn->next->next;
-         break;
+          break;
         }
       }
     }

This is not better it is consistent with the line width. We can increase the line width to avoid such changes.

@@ -219,7 +219,8 @@ static void on_vmnet_packets_available(interface_ref iface, int64_t estim_count,
          "r=%lld",
          estim_count, MAX_PACKET_COUNT_AT_ONCE, q, r);
   for (int i = 0; i < q; i++) {
-    _on_vmnet_packets_available(iface, MAX_PACKET_COUNT_AT_ONCE, max_bytes, state);
+    _on_vmnet_packets_available(iface, MAX_PACKET_COUNT_AT_ONCE, max_bytes,
+                                state);
   }
   if (r > 0)
     _on_vmnet_packets_available(iface, r, max_bytes, state);

This looks worse. The fix is to create a helper function and avoid the excessive nesting in the current code.

@@ -256,16 +257,17 @@ static interface_ref start(struct state *state, struct cli_options *cliopt) {
   __block vmnet_return_t status;
 
   __block uint64_t max_bytes = 0;
-  iface = vmnet_start_interface(
-      dict, state->host_queue, ^(vmnet_return_t x_status, xpc_object_t x_param) {
-        status = x_status;
-        if (x_status == VMNET_SUCCESS) {
-          print_vmnet_start_param(x_param);
-          max_bytes =
-              xpc_dictionary_get_uint64(x_param, vmnet_max_packet_size_key);
-        }
-        dispatch_semaphore_signal(sem);
-      });
+  iface =
+      vmnet_start_interface(dict, state->host_queue,
+                            ^(vmnet_return_t x_status, xpc_object_t x_param) {
+                              status = x_status;
+                              if (x_status == VMNET_SUCCESS) {
+                                print_vmnet_start_param(x_param);
+                                max_bytes = xpc_dictionary_get_uint64(
+                                    x_param, vmnet_max_packet_size_key);
+                              }
+                              dispatch_semaphore_signal(sem);
+                            });
   dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
   xpc_release(dict);
   if (status != VMNET_SUCCESS) {

This seems to fix the style to match other code, so we can take it.

-static void remove_pidfile(const char *pidfile)
-{
+static void remove_pidfile(const char *pidfile) {
   if (unlink(pidfile) != 0) {
     ERRORF("Failed to remove pidfile: \"%s\": %s", pidfile, strerror(errno));
     return;
@@ -362,8 +363,7 @@ static void remove_pidfile(const char *pidfile)
   INFOF("Removed pidfile \"%s\" for process %d", pidfile, getpid());
 }

Not sure why this uses more indentation but it looks good.

-static int setup_signals(int kq)
-{
+static int setup_signals(int kq) {
   struct kevent changes[] = {
-    { .ident=SIGHUP, .filter=EVFILT_SIGNAL, .flags=EV_ADD },
-    { .ident=SIGINT, .filter=EVFILT_SIGNAL, .flags=EV_ADD },
-    { .ident=SIGTERM, .filter=EVFILT_SIGNAL, .flags=EV_ADD },
+      {.ident = SIGHUP, .filter = EVFILT_SIGNAL, .flags = EV_ADD},
+      {.ident = SIGINT, .filter = EVFILT_SIGNAL, .flags = EV_ADD},
+      {.ident = SIGTERM, .filter = EVFILT_SIGNAL, .flags = EV_ADD},
   };

This looks fine, we can take this change or increase the line width.

     WARN("Running without root. This is very unlikely to work: See README.md");
   }
   if (geteuid() != getuid()) {
-    WARN("Seems running with SETUID. This is insecure and highly discouraged: See README.md");
+    WARN("Seems running with SETUID. This is insecure and highly discouraged: "
+         "See README.md");
   }

It is easier to work with the older format but the new format is automatic so we can go with the new one.

   // Queue for vm connections, allowing processing vms requests in parallel.
-  state.vms_queue = dispatch_queue_create(
-      "io.github.lima-vm.socket_vmnet.vms", DISPATCH_QUEUE_CONCURRENT);
+  state.vms_queue = dispatch_queue_create("io.github.lima-vm.socket_vmnet.vms",
+                                          DISPATCH_QUEUE_CONCURRENT);

@nirs
Copy link
Member

nirs commented Apr 2, 2025

@saurabhraghuvanshii I did not try other styles - maybe they match better the current code. It will be good idea to experiment with all existing styles and pick the one that need least amount of changes to the current code.

@saurabhraghuvanshii saurabhraghuvanshii force-pushed the Clang-format branch 2 times, most recently from 880e817 to dedbe95 Compare April 3, 2025 08:01
@saurabhraghuvanshii
Copy link
Contributor Author

saurabhraghuvanshii commented Apr 3, 2025

@saurabhraghuvanshii I did not try other styles - maybe they match better the current code. It will be good idea to experiment with all existing styles and pick the one that need least amount of changes to the current code

@nirs sir I tried other styles but they don't match much better, LLVM matches most and minimum changes required there I used It.

@saurabhraghuvanshii
Copy link
Contributor Author

I increased line width which is looks goods now , I think now .clang-format match our code . If any changes need I will do thanks for suggestion sir .

@saurabhraghuvanshii saurabhraghuvanshii force-pushed the Clang-format branch 2 times, most recently from 7254a34 to f20adc7 Compare April 3, 2025 12:13
@nirs
Copy link
Member

nirs commented Apr 3, 2025

I increased line width which is looks goods now , I think now .clang-format match our code . If any changes need I will do thanks for suggestion sir .

120 characters is too much and makes it harder to review diffs side by side or use git tools with small shell windows. We cannot assume that everyone is working in full screen mode on a large monitor. It is also bad for readability encouraging long variables names and lot of nesting.

I would keep the default line width for now and do minimal code change to make it work with the default LLVM format. We an consider larger line width in the next step.

@saurabhraghuvanshii
Copy link
Contributor Author

on running this llvm

saurabh@MSI:~/open-source-web/socket_vmnet$ clang-format -i *.c *.h client/*.c
saurabh@MSI:~/open-source-web/socket_vmnet$ git diff --stat
 cli.c         |  40 ++++++++++---------
 client/main.c |   6 +--
 log.h         |  20 +++++-----
 main.c        | 108 +++++++++++++++++++++++++--------------------------
 4 files changed, 88 insertions(+), 86 deletions(-)
saurabh@MSI:~/open-source-web/socket_vmnet$ 

@saurabhraghuvanshii
Copy link
Contributor Author

removed all unnecessary things from .clang-format , now I have see for arrays align , which I saw in document

@jandubois
Copy link
Member

120 characters is too much and makes it harder to review diffs side by side or use git tools with small shell windows. We cannot assume that everyone is working in full screen mode on a large monitor. It is also bad for readability encouraging long variables names and lot of nesting.

I would keep the default line width for now and do minimal code change to make it work with the default LLVM format. We an consider larger line width in the next step.

The default is just 80 columns, which is too short. Nobody uses punched cards or 3270 terminals anymore, and forcing the code into 80 columns results in ridiculous changes like these:

-    _on_vmnet_packets_available(iface, MAX_PACKET_COUNT_AT_ONCE, max_bytes, state);
+    _on_vmnet_packets_available(iface, MAX_PACKET_COUNT_AT_ONCE, max_bytes,
+                                state);-      ERRORF("vmnet_write: [%d] %s", write_status, vmnet_strerror(write_status));
+      ERRORF("vmnet_write: [%d] %s", write_status,
+             vmnet_strerror(write_status));

So maybe 120 is too long, but how about 100?

@jandubois
Copy link
Member

Okay sir, I will update I am thinking of asking this. But for clear i create new file. Thanks sir

This is informal collaboration on open source, not the military. There is no need to call anybody "sir". Maybe it is a cultural thing, but to me calling people "sir" in issues and PRs feels rather weird.

@saurabhraghuvanshii
Copy link
Contributor Author

120 characters is too much and makes it harder to review diffs side by side or use git tools with small shell windows. We cannot assume that everyone is working in full screen mode on a large monitor. It is also bad for readability encouraging long variables names and lot of nesting.
I would keep the default line width for now and do minimal code change to make it work with the default LLVM format. We an consider larger line width in the next step.

The default is just 80 columns, which is too short. Nobody uses punched cards or 3270 terminals anymore, and forcing the code into 80 columns results in ridiculous changes like these:

-    _on_vmnet_packets_available(iface, MAX_PACKET_COUNT_AT_ONCE, max_bytes, state);
+    _on_vmnet_packets_available(iface, MAX_PACKET_COUNT_AT_ONCE, max_bytes,
+                                state);-      ERRORF("vmnet_write: [%d] %s", write_status, vmnet_strerror(write_status));
+      ERRORF("vmnet_write: [%d] %s", write_status,
+             vmnet_strerror(write_status));

So maybe 120 is too long, but how about 100?

I tried 100 column it also break lines to next like 120.

@nirs
Copy link
Member

nirs commented Apr 4, 2025

120 characters is too much and makes it harder to review diffs side by side or use git tools with small shell windows. We cannot assume that everyone is working in full screen mode on a large monitor. It is also bad for readability encouraging long variables names and lot of nesting.
I would keep the default line width for now and do minimal code change to make it work with the default LLVM format. We an consider larger line width in the next step.

The default is just 80 columns, which is too short. Nobody uses punched cards or 3270 terminals anymore, and forcing the code into 80 columns results in ridiculous changes like these:

-    _on_vmnet_packets_available(iface, MAX_PACKET_COUNT_AT_ONCE, max_bytes, state);
+    _on_vmnet_packets_available(iface, MAX_PACKET_COUNT_AT_ONCE, max_bytes,
+                                state);-      ERRORF("vmnet_write: [%d] %s", write_status, vmnet_strerror(write_status));
+      ERRORF("vmnet_write: [%d] %s", write_status,
+             vmnet_strerror(write_status));

So maybe 120 is too long, but how about 100?

100 sounds good compromise, long enough to avoid unwanted line breaks and short enough to make it easy to compare side by side diffs and work with many smaller shell windows. This is also the width the Linux kernel chose as a hard limit recently. Adding the limit now will minimize the changes to needed to have automatic formatting.

Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by the CI results; how did a Windows path end up in here:

Run # Format all source - fi the source is formatted properly this will do nothing
Configuration file(s) do(es) not support C: /Users/runner/work/socket_vmnet/socket_vmnet/.clang-format
Configuration file(s) do(es) not support C: /Users/runner/work/socket_vmnet/socket_vmnet/.clang-format
Configuration file(s) do(es) not support C: /Users/runner/work/socket_vmnet/socket_vmnet/.clang-format
Error: Process completed with exit code 1.

@nirs
Copy link
Member

nirs commented Apr 4, 2025

I'm confused by the CI results; how did a Windows path end up in here:

Run # Format all source - fi the source is formatted properly this will do nothing
Configuration file(s) do(es) not support C: /Users/runner/work/socket_vmnet/socket_vmnet/.clang-format
Configuration file(s) do(es) not support C: /Users/runner/work/socket_vmnet/socket_vmnet/.clang-format
Configuration file(s) do(es) not support C: /Users/runner/work/socket_vmnet/socket_vmnet/.clang-format
Error: Process completed with exit code 1.

This is not windows path, I think it means that the configuration does not support the C language. Maybe because we call it with ".c" instead of ".cpp" or "*.cxx"?

I don't see this locally in macOS 15.3.2.

Lets try this:

brew update
brew install clang-format
clang-format --version

@nirs
Copy link
Member

nirs commented Apr 4, 2025

brew update
brew install clang-format
clang-format --version

Locally I have:

% clang-format --version
clang-format version 20.1.2

In the CI we install almost the same version:
Pouring clang-format--20.1.1.arm64_sequoia.bottle.tar.gz

So this is probably not the issue.

@nirs
Copy link
Member

nirs commented Apr 4, 2025

I tested this change in my fork and it works with some minor changes:
https://github.com/nirs/socket_vmnet/actions/runs/14271922180/job/40006878846

Changed .clang-format to :

---
Language: Cpp
BasedOnStyle: LLVM
AlignArrayOfStructures: Left
ColumnLimit: 100

And added proper indentation to the embedded script:

      - name: Check code
        run: |
          # Format all source - fi the source is formatted properly this will do nothing
          clang-format -i *.c *.h client/*.c

          # Do we have unwanted changes?
          if ! git diff-index --quiet HEAD; then
              # Show the changes
              echo "ERROR: Code is not properly formatted:"
              echo
              git --no-pager diff

              echo
              echo >&2 "Please run clang-format locally and commit the changes."
              exit 1
          fi  

I don't think this can change the buidl, but it works.

One issue - logging to stdout and stderr does not work - we get mixed output:

ERROR: Code is not properly formatted:

diff --git a/cli.c b/cli.c
index 2226a1e..4aeccc0 100644
--- a/cli.c
+++ b/cli.c
@@ -30,8 +30,7 @@ static void print_usage(const char *argv0) {
   printf("\n");
   printf("--socket-group=GROUP                socket group name (default: "
          "\"" CLI_DEFAULT_SOCKET_GROUP "\")\n");
-  printf(
-      "--vmnet-mode=(host|shared|bridged)  vmnet mode (default: \"shared\")\n");
+  printf("--vmnet-mode=(host|shared|bridged)  vmnet mode (default: \"shared\")\n");
   printf("--vmnet-interface=INTERFACE         interface used for "
          "--vmnet=bridged, e.g., \"en0\"\n");
   printf("--vmnet-gateway=IP                  gateway used for "
@@ -83,[18](https://github.com/nirs/socket_vmnet/actions/runs/14271922180/job/40006878846#step:4:19) +82,18 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
   }
 
   const struct option longopts[] = {
-    {"socket-group",        required_argument,  NULL,   CLI_OPT_SOCKET_GROUP},
-    {"vmnet-mode",          required_argument,  NULL,   CLI_OPT_VMNET_MODE},
-    {"vmnet-interface",     required_argument,  NULL,   CLI_OPT_VMNET_INTERFACE},
-    {"vmnet-gateway",       required_argument,  NULL,   CLI_OPT_VMNET_GATEWAY},
-    {"vmnet-dhcp-end",      required_argument,  NULL,   CLI_OPT_VMNET_DHCP_END},
-    {"vmnet-mask",          required_argument,  NULL,   CLI_OPT_VMNET_MASK},
-    {"vmnet-interface-id",  required_argument,  NULL,   CLI_OPT_VMNET_INTERFACE_ID},
-    {"vmnet-nat66-prefix",  required_argument,  NULL,   CLI_OPT_VMNET_NAT66_PREFIX},
-    {"pidfile",             required_argument,  NULL,   'p'},
-    {"help",                no_argument,        NULL,   'h'},
-    {"version",             no_argument,        NULL,   'v'},
-    {0, 0, 0, 0},
+      {"socket-group",       required_argument, NULL, CLI_OPT_SOCKET_GROUP      },
+      {"vmnet-mode",         required_argument, NULL, CLI_OPT_VMNET_MODE        },
+      {"vmnet-interface",    required_argument, NULL, CLI_OPT_VMNET_INTERFACE   },
Please run clang-format locally and commit the changes.
+      {"vmnet-gateway",      required_argument, NULL, CLI_OPT_VMNET_GATEWAY     },
+      {"vmnet-dhcp-end",     required_argument, NULL, CLI_OPT_VMNET_DHCP_END    },
+      {"vmnet-mask",         required_argument, NULL, CLI_OPT_VMNET_MASK        },

We should log everything to stdout or stderr, we cannot use both. Since logging to stderr is harder and, lets use only stdout.

@saurabhraghuvanshii
Copy link
Contributor Author

saurabhraghuvanshii commented Apr 4, 2025

I tested this change in my fork and it works with some minor changes: https://github.com/nirs/socket_vmnet/actions/runs/14271922180/job/40006878846

Changed .clang-format to :

---
Language: Cpp
BasedOnStyle: LLVM
AlignArrayOfStructures: Left
ColumnLimit: 100

And added proper indentation to the embedded script:

      - name: Check code
        run: |
          # Format all source - fi the source is formatted properly this will do nothing
          clang-format -i *.c *.h client/*.c

          # Do we have unwanted changes?
          if ! git diff-index --quiet HEAD; then
              # Show the changes
              echo "ERROR: Code is not properly formatted:"
              echo
              git --no-pager diff

              echo
              echo >&2 "Please run clang-format locally and commit the changes."
              exit 1
          fi  

I don't think this can change the buidl, but it works.

One issue - logging to stdout and stderr does not work - we get mixed output:

ERROR: Code is not properly formatted:

diff --git a/cli.c b/cli.c
index 2226a1e..4aeccc0 100644
--- a/cli.c
+++ b/cli.c
@@ -30,8 +30,7 @@ static void print_usage(const char *argv0) {
   printf("\n");
   printf("--socket-group=GROUP                socket group name (default: "
          "\"" CLI_DEFAULT_SOCKET_GROUP "\")\n");
-  printf(
-      "--vmnet-mode=(host|shared|bridged)  vmnet mode (default: \"shared\")\n");
+  printf("--vmnet-mode=(host|shared|bridged)  vmnet mode (default: \"shared\")\n");
   printf("--vmnet-interface=INTERFACE         interface used for "
          "--vmnet=bridged, e.g., \"en0\"\n");
   printf("--vmnet-gateway=IP                  gateway used for "
@@ -83,[18](https://github.com/nirs/socket_vmnet/actions/runs/14271922180/job/40006878846#step:4:19) +82,18 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
   }
 
   const struct option longopts[] = {
-    {"socket-group",        required_argument,  NULL,   CLI_OPT_SOCKET_GROUP},
-    {"vmnet-mode",          required_argument,  NULL,   CLI_OPT_VMNET_MODE},
-    {"vmnet-interface",     required_argument,  NULL,   CLI_OPT_VMNET_INTERFACE},
-    {"vmnet-gateway",       required_argument,  NULL,   CLI_OPT_VMNET_GATEWAY},
-    {"vmnet-dhcp-end",      required_argument,  NULL,   CLI_OPT_VMNET_DHCP_END},
-    {"vmnet-mask",          required_argument,  NULL,   CLI_OPT_VMNET_MASK},
-    {"vmnet-interface-id",  required_argument,  NULL,   CLI_OPT_VMNET_INTERFACE_ID},
-    {"vmnet-nat66-prefix",  required_argument,  NULL,   CLI_OPT_VMNET_NAT66_PREFIX},
-    {"pidfile",             required_argument,  NULL,   'p'},
-    {"help",                no_argument,        NULL,   'h'},
-    {"version",             no_argument,        NULL,   'v'},
-    {0, 0, 0, 0},
+      {"socket-group",       required_argument, NULL, CLI_OPT_SOCKET_GROUP      },
+      {"vmnet-mode",         required_argument, NULL, CLI_OPT_VMNET_MODE        },
+      {"vmnet-interface",    required_argument, NULL, CLI_OPT_VMNET_INTERFACE   },
Please run clang-format locally and commit the changes.
+      {"vmnet-gateway",      required_argument, NULL, CLI_OPT_VMNET_GATEWAY     },
+      {"vmnet-dhcp-end",     required_argument, NULL, CLI_OPT_VMNET_DHCP_END    },
+      {"vmnet-mask",         required_argument, NULL, CLI_OPT_VMNET_MASK        },

We should log everything to stdout or stderr, we cannot use both. Since logging to stderr is harder and, lets use only stdout.

we should remove >&2 for stdout it will give simple and clear stdout I think.

and for format check for .clang-format

- name: Validate .clang-format with yamllint
        run: |
          echo "Checking .clang-format for YAML syntax..."
          brew install yamllint
          yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" .clang-format

is it okay

@nirs
Copy link
Member

nirs commented Apr 4, 2025

  • name: Validate .clang-format with yamllint
    run: |
    echo "Checking .clang-format for YAML syntax..."
    brew install yamllint
    yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" .clang-format

I don't think it is needed since we one trivial yaml file, and the code checking it is longer than the actual file.

@nirs
Copy link
Member

nirs commented Apr 4, 2025

@saurabhraghuvanshii the CI output is very nice now!

To finish this change we need to:

  1. Squash all the commit into one
    • Run git rebase -i master
    • Change all lines (expect the first line) to start with "fixup" instead of "pick"
    • Save and exit
  2. Fix the commit message
    • The title should explain what this change is doing
    • The body should explain why
    • Have one Signed-off-by line at the end
  3. Add a commit changing the code format to make the CI pass
  4. Reorder the commits
    • Run git rebase -i master
    • Move the code change commit before the CI job commit

Signed-off-by: saurabhraghuvanshii <saurabhsraghuvanshi@gmail.com>
This change introduces a .clang-format file based on LLVM style with custom rules,
and adds a GitHub Actions CI job that checks on build of formatting code.

Signed-off-by: saurabhraghuvanshii <saurabhsraghuvanshi@gmail.com>
@saurabhraghuvanshii
Copy link
Contributor Author

@nirs done sir

Copy link
Member

@nirs nirs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jandubois jandubois dismissed their stale review April 6, 2025 06:53

Requested changes have been made

@jandubois jandubois merged commit 0e58990 into lima-vm:master Apr 6, 2025
10 checks passed
@jandubois jandubois added this to the v1.2.2 milestone Apr 6, 2025
@saurabhraghuvanshii
Copy link
Contributor Author

Thanks to all for supports and for improving my knowledge.

@saurabhraghuvanshii saurabhraghuvanshii deleted the Clang-format branch April 8, 2025 07:44
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate clang-format
4 participants