)]}'
{
  "commit": "cbdf5400a175139d2ddf1b695578d5baea7281e3",
  "tree": "923778212b32b1be3d71b02b18db85d462637e59",
  "parents": [
    "05d54a46b1c7d58ec352c7881fb13b8935931b4e"
  ],
  "author": {
    "name": "UebelAndre",
    "email": "github@uebelandre.com",
    "time": "Tue Sep 10 09:07:15 2024 -0700"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Tue Sep 10 16:07:15 2024 +0000"
  },
  "message": "Avoid double building `cargo_build_script.data` targets (#2826)\n\nBefore this change targets passed to `cargo_build_script.data` would get\nbuilt multiple times (once per configuration)\n```\n% bazel cquery \u0027filter(//test/cargo_build_script/location_expansion:target_data.txt, deps(//test/cargo_build_script/location_expansion:build_rs))\u0027\n//test/cargo_build_script/location_expansion:target_data.txt (be33641)\n//test/cargo_build_script/location_expansion:target_data.txt (a1c326f)\n```\nWe can see that this is the exec (`a1c326f`) and target (`be33641`)\nconfigurations.\n```\n% bazel config a1c326f be33641\nINFO: Displaying diff between configs a1c326f and be33641\nDisplaying diff between configs a1c326f and be33641\nFragmentOptions com.google.devtools.build.lib.analysis.PlatformOptions {\n  platforms: [@@internal_platforms_do_not_use//host:host], [@@bazel_tools//tools:host_platform]\n}\nFragmentOptions com.google.devtools.build.lib.analysis.config.CoreOptions {\n  compilation_mode: opt, fastbuild\n  is exec configuration: true, false\n  platform_suffix: exec, null\n}\nFragmentOptions com.google.devtools.build.lib.rules.android.AndroidConfiguration$Options {\n  fat_apk_cpu: [], [armeabi-v7a]\n}\nFragmentOptions com.google.devtools.build.lib.rules.cpp.CppOptions {\n  copt: [-g0], []\n  cxxopt: [-g0], []\n  strip: always, sometimes\n}\nFragmentOptions com.google.devtools.build.lib.rules.java.JavaOptions {\n  java_runtime_version: remotejdk_11, local_jdk\n  jvmopt: [-XX:ErrorFile\u003d/dev/stderr], []\n}\n```\n\nThis is caused by `data` being passed to the underlying rust binary in\n`cargo_build_script_wrapper.bzl`.\n\nThe fix for this ends up requiring some gymnastics as many existing uses\nof `cargo_build_script` rely on `data` files being available within the\nrunfiles of `cargo_build_script.script`. This change accounts for that\nby creating a wrapper rule for the build script that symlinks the\n`cfg\u003dexec` Rust binary (which is the actual [Cargo build\nscript](https://doc.rust-lang.org/cargo/reference/build-scripts.html))\nand updating the `cargo_build_script` rule to consume it as\n`cfg\u003dtarget`. Within the `cargo_build_script` rule this means the script\ntarget and it\u0027s `data` attribute files will be in `cfg\u003dtarget` but the\nbinary itself will have been built for `cfg\u003dexec` and will be runnable\non the exec platform.\n\nWe see after this change that data targets only appear once now\n```\n% bazel cquery \u0027filter(//test/cargo_build_script/location_expansion:target_data.txt, deps(//test/cargo_build_script/location_expansion:build_rs))\u0027\n//test/cargo_build_script/location_expansion:target_data.txt (be33641)\n```",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "66ad9128ce75d1ef72a0d922eae6b13bdb15d3b6",
      "old_mode": 33188,
      "old_path": "cargo/private/cargo_build_script.bzl",
      "new_id": "6c89b04fef1501cc5afb3a41bad0fbbf4f7ec34f",
      "new_mode": 33188,
      "new_path": "cargo/private/cargo_build_script.bzl"
    },
    {
      "type": "modify",
      "old_id": "1860e6127c7430869d7da307757a217fc60804bb",
      "old_mode": 33188,
      "old_path": "cargo/private/cargo_build_script_wrapper.bzl",
      "new_id": "c42f8819db8f8c3f2c84df7fa5635c7bc11812dc",
      "new_mode": 33188,
      "new_path": "cargo/private/cargo_build_script_wrapper.bzl"
    },
    {
      "type": "modify",
      "old_id": "9a2b05edb86f3f9a561b720a12f8d47bbcd08f1f",
      "old_mode": 33188,
      "old_path": "test/cargo_build_script/symlink_exec_root/test_exec_root_access.build.rs",
      "new_id": "b9615b020f849559ff3bb419a2791c3fa99ff704",
      "new_mode": 33188,
      "new_path": "test/cargo_build_script/symlink_exec_root/test_exec_root_access.build.rs"
    }
  ]
}
