From 7bf407ffd082b3d194c5e4effdb8e3da31956d53 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Fri, 3 Feb 2023 03:46:12 -0500 Subject: [PATCH 01/10] working `clangd` support in vscode, very nice --- BUILD.bazel | 24 ++++++++++++++++++++++++ WORKSPACE.bazel | 23 ++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/BUILD.bazel b/BUILD.bazel index 80d7445c27..7687e14d67 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -4,6 +4,8 @@ load("//bazel:common_settings.bzl", "string_flag") # OS-CPU CONFIG SETTINGS # +load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands") + config_setting( name = "linux_aarch64", constraint_values = [ @@ -179,3 +181,25 @@ alias( name = "urbit", actual = "//pkg/vere:urbit", ) + +# gazelle:exclude external + +refresh_compile_commands( + name = "refresh_compile_commands", + + # Specify the targets of interest. + # For example, specify a dict of targets and any flags required to build. + targets = [ + "//pkg/c3", + "//pkg/ent", + "//pkg/noun", + "//pkg/ur", + "//pkg/urcrypt", + "//pkg/vere:urbit", + ], + # No need to add flags already in .bazelrc. They're automatically picked up. + # If you don't need flags, a list of targets is also okay, as is a single target string. + # Wildcard patterns, like //... for everything, *are* allowed here, just like a build. + # As are additional targets (+) and subtractions (-), like in bazel query https://docs.bazel.build/versions/main/query.html#expressions + # And if you're working on a header-only library, specify a test or binary target that compiles it. +) diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index cde2522a44..61b73d8f5c 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -350,6 +350,23 @@ versioned_http_archive( version = "1.2.13", ) +# +# HEDRON COMPILE COMMANDS SETUP +# + +# Hedron's Compile Commands Extractor for Bazel +# https://github.com/hedronvision/bazel-compile-commands-extractor +versioned_http_archive( + name = "hedron_compile_commands", + strip_prefix = "bazel-compile-commands-extractor-{version}", + url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/{version}.tar.gz", + version = "d3afb5dfadd4beca48bb027112d029f2d34ff0a0", +) + +load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup") + +hedron_compile_commands_setup() + # # DOCKER SETUP # @@ -360,7 +377,9 @@ load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_depe load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") go_rules_dependencies() + go_register_toolchains(version = "1.18") + gazelle_dependencies(go_repository_default_config = "//:WORKSPACE.bazel") load( @@ -371,19 +390,21 @@ load("@io_bazel_rules_docker//repositories:deps.bzl", _container_deps = "deps") load("@io_bazel_rules_docker//cc:image.bzl", _cc_image_repos = "repositories") _container_repositories() + _container_deps( # See https://github.com/bazelbuild/rules_docker/issues/1902. go_repository_default_config = "@//:WORKSPACE.bazel", ) + _cc_image_repos() load("@io_bazel_rules_docker//container:container.bzl", "container_pull") container_pull( name = "alpine_linux_x86_64", + timeout = 300, # [seconds] architecture = "amd64", digest = "sha256:93d5a28ff72d288d69b5997b8ba47396d2cbb62a72b5d87cd3351094b5d578a0", registry = "docker.io", repository = "alpine", - timeout = 300, # [seconds] ) From 12b09d28cfc49364151a4a7a0b3a4bc9ac55a8c4 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Fri, 3 Feb 2023 04:04:41 -0500 Subject: [PATCH 02/10] add .vscode/settings.json --- .vscode/settings.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..d38a170e4d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "clangd.arguments": [ + "--header-insertion=never", + "--compile-commands-dir=${workspaceFolder}/", + "--query-driver=**", + ], +} \ No newline at end of file From 866635cbe167c43e5aa14f04231cfe1d81f0bf62 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Fri, 3 Feb 2023 04:05:55 -0500 Subject: [PATCH 03/10] remove bc it's just a library, not a binary target --- BUILD.bazel | 1 - 1 file changed, 1 deletion(-) diff --git a/BUILD.bazel b/BUILD.bazel index 7687e14d67..1c311a30f7 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -190,7 +190,6 @@ refresh_compile_commands( # Specify the targets of interest. # For example, specify a dict of targets and any flags required to build. targets = [ - "//pkg/c3", "//pkg/ent", "//pkg/noun", "//pkg/ur", From c76f32ffe3775ba9e38a8faf428b42f8ca1fb0c8 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 9 Feb 2023 10:22:24 -0500 Subject: [PATCH 04/10] remove `.vscode/` dir --- .vscode/settings.json | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index d38a170e4d..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "clangd.arguments": [ - "--header-insertion=never", - "--compile-commands-dir=${workspaceFolder}/", - "--query-driver=**", - ], -} \ No newline at end of file From e85d00c88c5d0ceea2f7019b4bb596b3d82d4865 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 9 Feb 2023 12:05:41 -0500 Subject: [PATCH 05/10] address peter's comments --- BUILD.bazel | 23 ----------------------- WORKSPACE.bazel | 1 + bazel/BUILD.bazel | 22 ++++++++++++++++++++++ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 1c311a30f7..80d7445c27 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -4,8 +4,6 @@ load("//bazel:common_settings.bzl", "string_flag") # OS-CPU CONFIG SETTINGS # -load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands") - config_setting( name = "linux_aarch64", constraint_values = [ @@ -181,24 +179,3 @@ alias( name = "urbit", actual = "//pkg/vere:urbit", ) - -# gazelle:exclude external - -refresh_compile_commands( - name = "refresh_compile_commands", - - # Specify the targets of interest. - # For example, specify a dict of targets and any flags required to build. - targets = [ - "//pkg/ent", - "//pkg/noun", - "//pkg/ur", - "//pkg/urcrypt", - "//pkg/vere:urbit", - ], - # No need to add flags already in .bazelrc. They're automatically picked up. - # If you don't need flags, a list of targets is also okay, as is a single target string. - # Wildcard patterns, like //... for everything, *are* allowed here, just like a build. - # As are additional targets (+) and subtractions (-), like in bazel query https://docs.bazel.build/versions/main/query.html#expressions - # And if you're working on a header-only library, specify a test or binary target that compiles it. -) diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 61b73d8f5c..146df200cb 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -359,6 +359,7 @@ versioned_http_archive( versioned_http_archive( name = "hedron_compile_commands", strip_prefix = "bazel-compile-commands-extractor-{version}", + sha256 = "d7ba7708816132f86f02864b9dba0c5abf249cc0fb035a34c430e4e538c87867", url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/{version}.tar.gz", version = "d3afb5dfadd4beca48bb027112d029f2d34ff0a0", ) diff --git a/bazel/BUILD.bazel b/bazel/BUILD.bazel index e69de29bb2..bb93f5d26c 100644 --- a/bazel/BUILD.bazel +++ b/bazel/BUILD.bazel @@ -0,0 +1,22 @@ +load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands") + +# gazelle:exclude external + +refresh_compile_commands( + name = "refresh_compile_commands", + + # Specify the targets of interest. + # For example, specify a dict of targets and any flags required to build. + targets = [ + "//pkg/ent", + "//pkg/noun", + "//pkg/ur", + "//pkg/urcrypt", + "//pkg/vere:urbit", + ], + # No need to add flags already in .bazelrc. They're automatically picked up. + # If you don't need flags, a list of targets is also okay, as is a single target string. + # Wildcard patterns, like //... for everything, *are* allowed here, just like a build. + # As are additional targets (+) and subtractions (-), like in bazel query https://docs.bazel.build/versions/main/query.html#expressions + # And if you're working on a header-only library, specify a test or binary target that compiles it. +) \ No newline at end of file From f13ad9f37f9d6ae33894ff0b326bafecaab22ac5 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 9 Feb 2023 12:29:37 -0500 Subject: [PATCH 06/10] add section to `CONTRIBUTING.md` about `clangd` LSP --- CONTRIBUTING.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f7600a52a9..8ed50760fd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -114,3 +114,29 @@ $ ./urbit [^1]: Unless you specify the pier using the `-c` flag. + +### Enable Language Server Processing + +We support the [`clangd`](https://clangd.llvm.org/installation) +language server, which can be installed directly on your system or +via one of the official editor plugins. + +After installing `clangd`, configure it to use the following arguments: + +```json +{ + "clangd.arguments": [ + "--header-insertion=never", + "--compile-commands-dir=${workspaceFolder}/", + "--query-driver=**", + ], +} +``` + +Finally, run the following command to generate a `compile_commands.json` file, +which is used by `clangd` to enable all of its features (e.g. code completion, +jump to definition, cross-references, hovering, symbol renaming, etc.): + +```console +bazel run //bazel:refresh_compile_commands +``` \ No newline at end of file From 9aaee7f2243e3e96a6f91826e2b4739703bdc72c Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 9 Feb 2023 17:00:49 -0500 Subject: [PATCH 07/10] clarify `clangd` argument instructions --- CONTRIBUTING.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8ed50760fd..c961af1198 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -121,7 +121,9 @@ We support the [`clangd`](https://clangd.llvm.org/installation) language server, which can be installed directly on your system or via one of the official editor plugins. -After installing `clangd`, configure it to use the following arguments: +After installing `clangd`, configure it to use the following arguments +(location of these arguments may vary depending on your editor plugin or +if you've installed `clangd` directly on your system): ```json { From 0d9a87eebb1d28bc7710b8462c6cc18399b9b675 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 9 Feb 2023 17:02:22 -0500 Subject: [PATCH 08/10] specify that the `clangd` arguments format is a vscode example --- CONTRIBUTING.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c961af1198..8b9b0ac71a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -125,6 +125,9 @@ After installing `clangd`, configure it to use the following arguments (location of these arguments may vary depending on your editor plugin or if you've installed `clangd` directly on your system): +For example, if you use Visual Studio Code, you can add the following to your +user settings: + ```json { "clangd.arguments": [ From a9bc1d33f56e3151010b5e7e3611cdbe40e4dc78 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 9 Feb 2023 17:02:39 -0500 Subject: [PATCH 09/10] typo --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8b9b0ac71a..8aa8b33c7d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -123,7 +123,7 @@ via one of the official editor plugins. After installing `clangd`, configure it to use the following arguments (location of these arguments may vary depending on your editor plugin or -if you've installed `clangd` directly on your system): +if you've installed `clangd` directly on your system). For example, if you use Visual Studio Code, you can add the following to your user settings: From 70d974dce987fbcbfd0bbccafd38a221039f4329 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 9 Feb 2023 17:05:10 -0500 Subject: [PATCH 10/10] editor plugin docs link --- CONTRIBUTING.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8aa8b33c7d..bf4df33aac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -138,6 +138,9 @@ user settings: } ``` +For other editors, please refer to the +[editor plugin documentation](https://clangd.llvm.org/installation.html#editor-plugins). + Finally, run the following command to generate a `compile_commands.json` file, which is used by `clangd` to enable all of its features (e.g. code completion, jump to definition, cross-references, hovering, symbol renaming, etc.):