{"id":20132537,"url":"https://github.com/aherrmann/bazel-toolchain-deps","last_synced_at":"2026-03-09T14:35:30.435Z","repository":{"id":71967614,"uuid":"337114521","full_name":"aherrmann/bazel-toolchain-deps","owner":"aherrmann","description":null,"archived":false,"fork":false,"pushed_at":"2021-09-10T10:06:26.000Z","size":5,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-13T09:10:07.102Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Starlark","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aherrmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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},"funding":{"open_collective":"bazel-rules-authors-sig"}},"created_at":"2021-02-08T15:09:18.000Z","updated_at":"2021-09-27T05:45:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"9d107d0e-2cf3-4a63-9901-984d4a825b4c","html_url":"https://github.com/aherrmann/bazel-toolchain-deps","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aherrmann%2Fbazel-toolchain-deps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aherrmann%2Fbazel-toolchain-deps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aherrmann%2Fbazel-toolchain-deps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aherrmann%2Fbazel-toolchain-deps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aherrmann","download_url":"https://codeload.github.com/aherrmann/bazel-toolchain-deps/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241577174,"owners_count":19984951,"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":[],"created_at":"2024-11-13T20:53:57.105Z","updated_at":"2026-03-09T14:35:25.408Z","avatar_url":"https://github.com/aherrmann.png","language":"Starlark","funding_links":["https://opencollective.com/bazel-rules-authors-sig"],"categories":[],"sub_categories":[],"readme":"# Toolchains Depending on Other Toolchains\n\nSome compiler toolchains depend on other compiler toolchains. E.g. the Haskell\ncompiler GHC requires a C compiler and linker to build Haskell binaries.\n\nIn Bazel this can be expressed as a toolchain for the Haskell compiler and a\nseparate toolchain for the C compiler. However, one needs to take care to\nexpress dependency between these toolchains correctly. Otherwise, Bazel will\nresolve the wrong C toolchain in a cross compilation setup.\n\nThe correct setup is to have the final targets, i.e. the `haskell_binary` rule,\ndepend on both toolchains. *Not*, to have the Haskell toolchain depend on the C\ntoolchain.\n\nThis is illustrated in the following two examples:\n\n## The Wrong Way\n\nThe example in `toolchain-on-toolchain` illustrates the wrong setup.\n\nThe following command asks Bazel to build `//:hs` on the current platform\n(x86_64 Linux) targetting a different platform (ARM Linux).\n\n```\n$ bazel build //:hs --platforms //platform:linux_arm\n...\n! Haskell compiler\n! Running on x86_64 linux\n! Targetting arm linux\n! Using CC bazel-out/host/bin/cc/cc_linux_x86_64\n! CC compiler\n! Running on x86_64 linux\n! Targetting x86_64 linux\n...\n```\n\nWe can see that the Haskell compiler is resolved correctly. But, the C compiler\nis not. The C compiler should run on x86_64 Linux but target ARM Linux.\n\nThe reason is that in this setup the Haskell toolchain itself depends on the C\ntoolchain. So, Bazel will not resolve the C toolchain targetting `//:hs`'s\ntarget platform, but instead the platform which the Haskell toolchain is\nsupposed to *execute* on, in this case x86_64 Linux.\n\n## The Correct Way\n\nThe example in `target-on-toolchain` illustrates the correct setup.\n\nThe following command asks Bazel to build `//:hs` on the current platform\n(x86_64 Linux) targetting a different platform (ARM Linux).\n\n```\n$ bazel clean \u0026\u0026 bazel build //:hs --platforms //platform:linux_arm\n...\n! Haskell compiler\n! Running on x86_64 linux\n! Targetting arm linux\n! Using CC bazel-out/host/bin/cc/cc_linux_x86_64_cross_arm\n! CC compiler\n! Running on x86_64 linux\n! Targetting arm linux\n...\n```\n\nWe can see that the Haskell compiler is resolved correctly and the C compiler\nas well. Both run on x86_64 Linux and target ARM Linux.\n\nThe reason is that in this setup it is the target, the `haskell_binary`\n`//:hs`, that depends on both toolchains. So, Bazel will resolve both\ntoolchains to execute on the execution platform x86_64 Linux and to target the\ntarget platform ARM Linux.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faherrmann%2Fbazel-toolchain-deps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faherrmann%2Fbazel-toolchain-deps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faherrmann%2Fbazel-toolchain-deps/lists"}