From da93cf070b93292ad6132313b3f0669edef613cd Mon Sep 17 00:00:00 2001 From: Nick Dumas Date: Tue, 25 Jul 2023 19:52:25 -0400 Subject: [PATCH] gazelle works, tests work --- BUILD => BUILD.bazel | 15 ++++++-- WORKSPACE | 45 +++++++---------------- cmd/demo/BUILD.bazel | 18 +++++++++ deps.bzl | 87 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 34 deletions(-) rename BUILD => BUILD.bazel (74%) create mode 100644 cmd/demo/BUILD.bazel create mode 100644 deps.bzl diff --git a/BUILD b/BUILD.bazel similarity index 74% rename from BUILD rename to BUILD.bazel index 847cdda..6cace17 100644 --- a/BUILD +++ b/BUILD.bazel @@ -1,12 +1,20 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") - -package(default_visibility = ["//visibility:public"]) - load("@bazel_gazelle//:def.bzl", "gazelle") # gazelle:prefix code.ndumas.com/ndumas/obsidian-markdown gazelle(name = "gazelle") +gazelle( + name = "gazelle-update-repos", + args = [ + "-from_file=go.mod", + "-to_macro=deps.bzl%go_dependencies", + "-prune", + "-build_file_proto_mode=disable_global", + ], + command = "update-repos", +) + go_library( name = "obsidian-markdown", srcs = [ @@ -16,6 +24,7 @@ go_library( "wikilink.go", ], importpath = "code.ndumas.com/ndumas/obsidian-markdown", + visibility = ["//visibility:public"], deps = [ "@org_uber_go_zap//:go_default_library", "@org_uber_go_zap//zapcore:go_default_library", diff --git a/WORKSPACE b/WORKSPACE index 26e7717..6f43f20 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -2,53 +2,36 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "io_bazel_rules_go", - sha256 = "69de5c704a05ff37862f7e0f5534d4f479418afc21806c887db544a316f3cb6b", + sha256 = "6dc2da7ab4cf5d7bfc7c949776b1b7c733f05e56edc4bcd9022bb249d2e2a996", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.27.0/rules_go-v0.27.0.tar.gz", - "https://github.com/bazelbuild/rules_go/releases/download/v0.27.0/rules_go-v0.27.0.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip", ], ) http_archive( name = "bazel_gazelle", - sha256 = "62ca106be173579c0a167deb23358fdfe71ffa1e4cfdddf5582af26520f1c66f", + sha256 = "727f3e4edd96ea20c29e8c2ca9e8d2af724d8c7778e7923a854b2c80952bc405", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.30.0/bazel-gazelle-v0.30.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.30.0/bazel-gazelle-v0.30.0.tar.gz", ], ) load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") +load("//:deps.bzl", "go_dependencies") +# gazelle:repository_macro deps.bzl%go_dependencies +go_dependencies() +############################################################ +# Define your own dependencies here using go_repository. +# Else, dependencies declared by rules_go/gazelle will be used. +# The first declaration of an external repository "wins". +############################################################ go_rules_dependencies() go_register_toolchains(version = "1.20.5") gazelle_dependencies() - -# release notes at https://github.com/bazelbuild/rules_docker/releases -http_archive( - name = "io_bazel_rules_docker", - sha256 = "59d5b42ac315e7eadffa944e86e90c2990110a1c8075f1cd145f487e999d22b3", - strip_prefix = "rules_docker-0.17.0", - urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.17.0/rules_docker-v0.17.0.tar.gz"], -) - -load( - "@io_bazel_rules_docker//repositories:repositories.bzl", - container_repositories = "repositories", -) -container_repositories() - -load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps") - -container_deps() - -load( - "@io_bazel_rules_docker//go:image.bzl", - _go_image_repos = "repositories", -) - -_go_image_repos() diff --git a/cmd/demo/BUILD.bazel b/cmd/demo/BUILD.bazel new file mode 100644 index 0000000..ae2465f --- /dev/null +++ b/cmd/demo/BUILD.bazel @@ -0,0 +1,18 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") + +go_library( + name = "demo_lib", + srcs = ["main.go"], + importpath = "code.ndumas.com/ndumas/obsidian-markdown/cmd/demo", + visibility = ["//visibility:private"], + deps = [ + "//:obsidian-markdown", + "@org_uber_go_zap//zapcore:go_default_library", + ], +) + +go_binary( + name = "demo", + embed = [":demo_lib"], + visibility = ["//visibility:public"], +) diff --git a/deps.bzl b/deps.bzl new file mode 100644 index 0000000..2e958c5 --- /dev/null +++ b/deps.bzl @@ -0,0 +1,87 @@ +load("@bazel_gazelle//:deps.bzl", "go_repository") + +def go_dependencies(): + go_repository( + name = "com_github_benbjohnson_clock", + build_file_proto_mode = "disable_global", + importpath = "github.com/benbjohnson/clock", + sum = "h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=", + version = "v1.1.0", + ) + go_repository( + name = "com_github_davecgh_go_spew", + build_file_proto_mode = "disable_global", + importpath = "github.com/davecgh/go-spew", + sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=", + version = "v1.1.1", + ) + go_repository( + name = "com_github_pkg_errors", + build_file_proto_mode = "disable_global", + importpath = "github.com/pkg/errors", + sum = "h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=", + version = "v0.8.1", + ) + go_repository( + name = "com_github_pmezard_go_difflib", + build_file_proto_mode = "disable_global", + importpath = "github.com/pmezard/go-difflib", + sum = "h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=", + version = "v1.0.0", + ) + go_repository( + name = "com_github_stretchr_objx", + build_file_proto_mode = "disable_global", + importpath = "github.com/stretchr/objx", + sum = "h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=", + version = "v0.4.0", + ) + go_repository( + name = "com_github_stretchr_testify", + build_file_proto_mode = "disable_global", + importpath = "github.com/stretchr/testify", + sum = "h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=", + version = "v1.8.0", + ) + go_repository( + name = "in_gopkg_check_v1", + build_file_proto_mode = "disable_global", + importpath = "gopkg.in/check.v1", + sum = "h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=", + version = "v0.0.0-20161208181325-20d25e280405", + ) + go_repository( + name = "in_gopkg_yaml_v3", + build_file_proto_mode = "disable_global", + importpath = "gopkg.in/yaml.v3", + sum = "h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=", + version = "v3.0.1", + ) + go_repository( + name = "org_uber_go_atomic", + build_file_proto_mode = "disable_global", + importpath = "go.uber.org/atomic", + sum = "h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=", + version = "v1.7.0", + ) + go_repository( + name = "org_uber_go_goleak", + build_file_proto_mode = "disable_global", + importpath = "go.uber.org/goleak", + sum = "h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=", + version = "v1.1.11", + ) + go_repository( + name = "org_uber_go_multierr", + build_file_proto_mode = "disable_global", + importpath = "go.uber.org/multierr", + sum = "h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=", + version = "v1.6.0", + ) + go_repository( + name = "org_uber_go_zap", + build_file_proto_mode = "disable_global", + importpath = "go.uber.org/zap", + sum = "h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=", + version = "v1.24.0", + )