{"id":24668852,"url":"https://github.com/linuxerwang/gobazel","last_synced_at":"2025-10-08T05:31:51.351Z","repository":{"id":57527036,"uuid":"73564088","full_name":"linuxerwang/gobazel","owner":"linuxerwang","description":"gobazel is a tool to help golang bazel developers to map bazel's folder structure to golang's standard folder structure, through FUSE (thus only works for Linux and MacOS users).","archived":false,"fork":false,"pushed_at":"2018-07-23T01:03:44.000Z","size":36,"stargazers_count":27,"open_issues_count":2,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-07T22:03:47.156Z","etag":null,"topics":["bazel","fuse","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linuxerwang.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}},"created_at":"2016-11-12T16:27:01.000Z","updated_at":"2023-11-02T04:09:36.000Z","dependencies_parsed_at":"2022-09-07T05:31:07.638Z","dependency_job_id":null,"html_url":"https://github.com/linuxerwang/gobazel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/linuxerwang/gobazel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxerwang%2Fgobazel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxerwang%2Fgobazel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxerwang%2Fgobazel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxerwang%2Fgobazel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linuxerwang","download_url":"https://codeload.github.com/linuxerwang/gobazel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxerwang%2Fgobazel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278892178,"owners_count":26063943,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","fuse","golang"],"created_at":"2025-01-26T09:17:46.759Z","updated_at":"2025-10-08T05:31:51.039Z","avatar_url":"https://github.com/linuxerwang.png","language":"Go","readme":"# gobazel\n\ngobazel is a tool to help golang bazel developers to map bazel's folder\nstructure to golang's standard folder structure, through FUSE \u0026 FsNotify\n(thus only works for Linux users).\n\n## Why gobazel\n\nFirst, I love to use [bazel](https://bazel.io) and\n[rules_go](https://github.com/bazelbuild/rules_go) to manage my projects.\nBazel is created by Google for huge amounts of inter-related projects\n(imagine you have thousands of projects and they depend on each other in\nthe most complex way). Besides the many great features of Bazel, its way\nof dependency management makes it much easier to manage such projects.\n\n### What's the Problem with bazel (and rules_go)?\n\nBazel's folder layout is very different from most existing languages,\nthus causes many problems for developers. The top issue is the poor IDE\nand tools support. Bazel team released demo plugins for Eclipse and Intellij,\nbut none of them works smoothly for me.\n\nFor Golang programming, the problem is much worse. The standard Golang project\nstructure is with a GOPATH, in which three standard folders are expected: bin,\npkg, and src. All source codes are put in src folder, both your code and the\ndependant 3rd-party code. The following shows a typical GOPATH layout:\n\n```\n$TOP\n  |- bin/\n  |- pkg/\n  |- src/\n      |- github.com/\n      |   |- ...\n      |\n      |- mycompany.com/\n          |- my-prod-1/\n          |- my-prod-2/\n          |- my-prod-3/\n          |- ...\n```\n\nIn comparison, the same projects can be organized better with bazel:\n\n```\n$TOP\n  |- bazel-bin/\n  |- bazel-genfiles/\n  |- ...\n  |- my-prod-1/\n  |- my-prod-2/\n  |- my-prod-3/\n  |- ...\n  |- third-party-go/\n  |   |- vendor/\n  |       |- github.com/\n  |           |- ...\n  |- WORKSPACE\n```\n\nrules_go lets you specify a Go package prefix, for example \"mycompany.com\",\nwhich is not represented in the above layout. Instead, rules_go uses certain\ntechniques to trick the Go compiler to work the prefix around.\n\nIt causes serious problems because there is no GOPATH any more, and most of\nthe existing Golang tools depend on the GOPATH! So now godoc stops working,\ngo-guru stops working, and most IDEs stop working.\n\n### gobazel to the Rescue\n\nSo Go tools and IDEs requires a GOPATH, which is not in alignment with bazel's\nway of organizing source codes. That's why gobazel was born: utilizing the\nFUSE virtual file system, it simulates a $GOPATH/src by mapping folders\nproperly, thus satisfies both sides:\n\n- A top folder outside of bazel workspace should be created as the GOPATH.\n\n- Within $GOPATH three folders should be created: bin, src, pkg.\n\n- FUSE mount the virtual file system on $GOPATH/src.\n\n- A $GOPATH/src/\u003cgo-pkg-prefix\u003e is simulated, such as:\n\t$GOPATH/src/mycompany.com.\n\n- All top level folders (my-prod-1, ...) except the third-party-go will\n\tbe mapped under $GOPATH/src/\u003cgo-pkg-prefix\u003e.\n\n- All folders under third-party-go/vendor will be mapped to under $GOPATH/src.\n\n- The bazel-* links will be ignored, except that all entries in bazel-genfiles\n\twill be mapped under $GOPATH/src/\u003cgo-pkg-prefix\u003e.\n\nOnce the above has been done, the GOPATH can be set to the new top folder and\neverything else will just work by itself, because from Golang tools it's\nsimply a real GOPATH.\n\n## Installation and Setup\n\n```bash\n$ go get github.com/linuxerwang/gobazel\n```\n\nMake sure the compiled command \"gobazel\" be put into your $PATH. Yes, you\nneed a normal GOPATH to go get gobazel. Once you get the command, you don't\nneed this GOPATH any more.\n\nNext, make a new empty GOPATH. Suppose your bazel workspace is at ~/my-bazel\nand your Go package prefix is \"mycompany.com\". You could create it at\n~/my-bazel-gopath.\n\nExecute command \"gobazel\" under ~/my-bazel:\n\n```bash\nme@laptop:~/my-bazel$ gobazel\nCreated gobazel config file /home/me/my-bazel/.gobazelrc,\nplease customize it and run the command again.\n```\n\nCustomize the file .gobazelrc to fit your layout. Mine looks like:\n\n```\ngobazel {\n    go-path: \"/home/me/my-bazel-gopath\"\n    go-pkg-prefix: \"mycompany.com\"\n    go-ide-cmd: \"/usr/bin/atom\"\n    # go-ide-cmd: \"/home/tools/liteide/bin/liteide\"\n\n    vendor-dirs: [\n        \"third-party-go/vendor\",\n    ]\n\n    ignore-dirs: [\n        \"bazel-.*\",\n        \"third-party.*\",\n    ]\n\n    fall-through-dirs: [\n        \".vscode\",\n    ]\n}\n```\n\nYou can set up your favorite IDE, or specify empty.\n\nThe last step, execute \"gobazel\" command again (in the bazel workspace),\nand you should see the IDE launched and everything worked.\n\nFlag --build enables gobazel to build all bazel targets which satisfy the\ngiven criteria. An example config looks as follows:\n\n```\ngobazel {\n    ...\n\n    build {\n        rules: [\n            \"genproto_go\",\n        ]\n        ignore-dirs: [\n            \"bazel-.*\",\n            \"third-party.*\",\n        ]\n    }\n\n    ...\n}\n\n```\n\nFlag --debug enables gobazel to print out verbose debug information.\n\n## Remote Debug with Delve (dlv)\n\nStart your binary with dlv:\n\n```bash\n$ dlv exec bazel-bin/myserver/cmd/myserver/myserver --headless --listen=:2345 --log [-- \u003cother-args\u003e]\n```\n\nIn VS code, add a debug configuration:\n\n```js\n{\n    \"version\": \"0.2.0\",\n    \"configurations\": [\n        {\n            \"name\": \"bazel-bin/myserver/cmd/myserver/myserver\",\n            \"type\": \"go\",\n            \"request\": \"launch\",\n            \"mode\": \"remote\",\n            \"remotePath\": \"/home/linuxerwang/.cache/bazel/_bazel_linuxerwang/eedeac95b950221f7e2a454b8c435113/bazel-sandbox/93167466216111235/execroot/__main__\",\n            \"port\": 2345,\n            \"host\": \"127.0.0.1\",\n            \"program\": \"${workspaceRoot}/mycompany.com\",\n            \"env\": {},\n            \"args\": []\n        }\n    ]\n}\n```\n\nThe \"remotePath\" field can be extracted with gdb:\n\n```\n$ gdb bazel-bin/myserver/cmd/myserver/myserver -batch -ex \"list\" -ex \"info source\"\nwarning: Missing auto-load script at offset 0 in section .debug_gdb_scripts of file /home/linuxerwang/.cache/bazel/_bazel_linuxerwang/eedeac95b950221f7e2a454b8c435113/execroot/__main__/bazel-out/k8-dbg/bin/myserver/cmd/myserver/myserver.\nUse `info auto-load python-scripts [REGEXP]' to list them.\nwarning: Source file is more recent than executable.\n24              flagFile        = flag.String(\"f\", \"\", \"The CSV file\")\n25\n26              success, failure int32\n27      )\n28\n29      func usage() {\n30              fmt.Println(\"Usage:\")\nCurrent source file is myserver/cmd/myserver/main.go\nCompilation directory is /home/linuxerwang/.cache/bazel/_bazel_linuxerwang/eedeac95b950221f7e2a454b8c435113/bazel-sandbox/93167466216111235/execroot/__main__\nLocated in /home/linuxerwang/my-client/myserver/cmd/myserver/main.go\nContains 129 lines.\nSource language is asm.\nProducer is Go cmd/compile go1.9.2.\nCompiled with DWARF 2 debugging format.\nDoes not include preprocessor macro info.\n```\n\nNote that the path is in the line starting with \"Compilation directory\".\n\nNow you can do remote debug in vscode with F5. It can trace the Go-SDK (using\nthe Go-SDK in bazel external directory) and third party code correctly.\n\n## Caveates\n\n- At present it only works on Linux and OSX (thanks excavador for adding the OSX\n    support). It requires FUSE, fsnotify.\n\n- It works for Golang programming with bazel. Might also work for Java\n\tafter code change (not planned for now).\n\n- Do not change files both in bazel workspace and in the simulated GOPATH!\n\tAt right now the fsnotify doesn't work between the simulated GOPATH\n\tand bazel workspace. So if a file is changed in bazel workspace,\n\tthe IDE (on simulated GOPATH) will not notice the change thus you might\n\toverwrite files accidentally (and even without realizing it). Some\n\treference documents:\n\n\t- https://github.com/libfuse/libfuse/wiki/Fsnotify-and-FUSE\n\t- https://www.howtoforge.com/tutorial/monitoring-file-changes-with-linux-over-the-network/\n\n\tI didn't make it work. Fix's welcome.\n\n- For files generated in bazel-genfiles, you have to manually run bazel\n\tcommand in bazel workspace. gobazel will not automatically run it.\n\n- Tested on LiteIDE and Atom. Tested godoc, go-guru.\n\n- The file deletion in Atom is through moving to trash, which is not\n\tsupported in gobazel. You can install the package \"permanent-delete\":\n\thttps://atom.io/packages/permanent-delete.\n\n## Acknowledgement\n\n- FUSE bindings for Go: https://github.com/hanwen/go-fuse\n- File system event notification: https://github.com/rjeczalik/notify\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinuxerwang%2Fgobazel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinuxerwang%2Fgobazel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinuxerwang%2Fgobazel/lists"}