{"id":19614687,"url":"https://github.com/activestate/rules_vendor","last_synced_at":"2025-04-28T01:32:15.004Z","repository":{"id":66048047,"uuid":"145139468","full_name":"ActiveState/rules_vendor","owner":"ActiveState","description":"Bazel support for packaging Go vendored dependencies","archived":false,"fork":false,"pushed_at":"2019-11-03T21:15:54.000Z","size":27,"stargazers_count":3,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T04:51:18.601Z","etag":null,"topics":["bazel","bazel-rules","dependencies","godep","golang"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ActiveState.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-17T15:51:05.000Z","updated_at":"2022-07-30T08:38:51.000Z","dependencies_parsed_at":"2023-07-09T07:30:50.528Z","dependency_job_id":null,"html_url":"https://github.com/ActiveState/rules_vendor","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ActiveState%2Frules_vendor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ActiveState%2Frules_vendor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ActiveState%2Frules_vendor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ActiveState%2Frules_vendor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ActiveState","download_url":"https://codeload.github.com/ActiveState/rules_vendor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251234107,"owners_count":21556785,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bazel","bazel-rules","dependencies","godep","golang"],"created_at":"2024-11-11T10:53:21.937Z","updated_at":"2025-04-28T01:32:14.989Z","avatar_url":"https://github.com/ActiveState.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bazel Rules for Golang Vendored Dependencies\n\n### Overview\n\nThis repository contains a set of rules which allow you to build Go [vendor\ndirectories](https://golang.org/cmd/go/#hdr-Vendor_Directories) as a native,\nlabelled [Bazel](https://bazel.build) package instead of building them inline\nfrom your project repository\n\nWith this rule, your `BUILD.bazel` deps for vendor packages will change from:\n\n```\n//vendor/github.com/organization/repo:tag:go_default_library\n```\n\nto this form:\n\n```\n@vendor//vendor/github.com/organization/repo:tag:go_default_library\n```\n\nThis moves all the vendored dependencies to a Bazel label so that they can\nreferenced identically even across multiple packages within your Bazel build\nworkspace.  This is particularly useful for packaged, generated code like when\nusing [go-swagger](https://goswagger.io) where it's necessary to share a common\nset of vendor dependencies across the Bazel package boundaries.\n\nThis allows the generated code and the main project code to identically import\ndeps from a consistent Bazel import path, which is necesary to keep Bazel\nconsistent and caching effectively.  It also prevents errors arising from\nstructures being passed across package boundaries introducing namespace\nconflicts.\n\nBuilding the vendor package is driven by your `Gopkg.lock` file, so unnecessary\nrebuilds will be avoided until the lock file is updated.\n\n### Setup\n\nAdd the following to your `WORKSPACE` file to load the rules and track your\nvendor directory:\n\n```python\nhttp_archive(\n    name = \"com_activestate_rules_vendor\",\n    urls = [\"https://github.com/ActiveState/rules_vendor/archive/v0.1.3.tar.gz\"],\n    sha256 = \"2f87901be842aac9d1327299dd3016d05752351498ab1b26f132c1a592ee4946\",\n    strip_prefix = \"rules_vendor-0.1.3\",\n)\nload(\"@com_activestate_rules_vendor//:def.bzl\", \"vendor_dependencies\", \"vendor_generate\")\nvendor_dependencies()\n\nvendor_generate(\n    name = \"vendor\",\n    src = \"//:Gopkg.lock\",\n    importpath = \"github.com/orgname/repo\",\n) \n```\n\nIn the `BUILD.bazel` file at your project root, add the following:\n\n```python\nexports_files([\"Gopkg.lock\", \"Gopkg.yaml\"])\n```\n\nThis should also work fine exporting `go.mod` and `go.sum` if you are using\nGo Modules instead of dep.  Just change the corresponding `src` label in your\nWORKSPACE `vendor_generate` to match.\n\n### Caveats\n\nIdeally this will be paired with an extension to\n[Gazelle](https://github.com/bazelbuild/bazel-gazelle) to write the correct\nform for the deps to your build files.  For now, though, you will probably find\nit useful to post-process Gazelle-maintained build files with something along\nthese lines:\n\n```\nbazel run //:gazelle\nfind . -name BUILD.bazel | xargs sed -ibak 's%\"//vendor%\"@vendor//vendor%'\nfind . -name BUILD.bazelbak -delete\n```\n\nThis is admittedly unwieldy, but it's functional.  A more elegant solution is\non the roadmap.\n\nYou will also want to make sure that you exclude your vendor directory from\nbeing processed by Gazelle by placing this in your BUILD file as well.\n\n```\n# gazelle:exclude vendor\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factivestate%2Frules_vendor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Factivestate%2Frules_vendor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factivestate%2Frules_vendor/lists"}