diff --git a/MODULE.bazel b/MODULE.bazel index e287e06..17997e2 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,16 +1,7 @@ # MODULE.bazel module( name = "rules_cc_resources", - version = "0.2.0", + version = "0.3.0", ) -bazel_dep(name = "rules_cc", version = "0.1.1") -bazel_dep(name = "rules_python", version = "1.4.1") - -# Setup Python toolchain (required by rules_python) -python = use_extension("@rules_python//python:extensions.bzl", "python") -python.toolchain( - name = "python_toolchain", - python_version = "3.11", -) -use_repo(python, "python_toolchain") +bazel_dep(name = "rules_cc", version = "0.2.14") diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 8fa8e09..6524e33 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -16,8 +16,9 @@ "https://bcr.bazel.build/modules/bazel_features/1.17.0/MODULE.bazel": "039de32d21b816b47bd42c778e0454217e9c9caac4a3cf8e15c7231ee3ddee4d", "https://bcr.bazel.build/modules/bazel_features/1.18.0/MODULE.bazel": "1be0ae2557ab3a72a57aeb31b29be347bcdc5d2b1eb1e70f39e3851a7e97041a", "https://bcr.bazel.build/modules/bazel_features/1.19.0/MODULE.bazel": "59adcdf28230d220f0067b1f435b8537dd033bfff8db21335ef9217919c7fb58", - "https://bcr.bazel.build/modules/bazel_features/1.21.0/MODULE.bazel": "675642261665d8eea09989aa3b8afb5c37627f1be178382c320d1b46afba5e3b", - "https://bcr.bazel.build/modules/bazel_features/1.21.0/source.json": "3e8379efaaef53ce35b7b8ba419df829315a880cb0a030e5bb45c96d6d5ecb5f", + "https://bcr.bazel.build/modules/bazel_features/1.28.0/MODULE.bazel": "4b4200e6cbf8fa335b2c3f43e1d6ef3e240319c33d43d60cc0fbd4b87ece299d", + "https://bcr.bazel.build/modules/bazel_features/1.30.0/MODULE.bazel": "a14b62d05969a293b80257e72e597c2da7f717e1e69fa8b339703ed6731bec87", + "https://bcr.bazel.build/modules/bazel_features/1.30.0/source.json": "b07e17f067fe4f69f90b03b36ef1e08fe0d1f3cac254c1241a1818773e3423bc", "https://bcr.bazel.build/modules/bazel_features/1.4.1/MODULE.bazel": "e45b6bb2350aff3e442ae1111c555e27eac1d915e77775f6fdc4b351b758b5d7", "https://bcr.bazel.build/modules/bazel_features/1.9.1/MODULE.bazel": "8f679097876a9b609ad1f60249c49d68bfab783dd9be012faf9d82547b14815a", "https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8", @@ -54,7 +55,6 @@ "https://bcr.bazel.build/modules/protobuf/27.0/MODULE.bazel": "7873b60be88844a0a1d8f80b9d5d20cfbd8495a689b8763e76c6372998d3f64c", "https://bcr.bazel.build/modules/protobuf/27.1/MODULE.bazel": "703a7b614728bb06647f965264967a8ef1c39e09e8f167b3ca0bb1fd80449c0d", "https://bcr.bazel.build/modules/protobuf/29.0-rc2/MODULE.bazel": "6241d35983510143049943fc0d57937937122baf1b287862f9dc8590fc4c37df", - "https://bcr.bazel.build/modules/protobuf/29.0-rc3/MODULE.bazel": "33c2dfa286578573afc55a7acaea3cada4122b9631007c594bf0729f41c8de92", "https://bcr.bazel.build/modules/protobuf/29.0/MODULE.bazel": "319dc8bf4c679ff87e71b1ccfb5a6e90a6dbc4693501d471f48662ac46d04e4e", "https://bcr.bazel.build/modules/protobuf/29.0/source.json": "b857f93c796750eef95f0d61ee378f3420d00ee1dd38627b27193aa482f4f981", "https://bcr.bazel.build/modules/protobuf/3.19.0/MODULE.bazel": "6b5fbb433f760a99a22b18b6850ed5784ef0e9928a72668b66e4d7ccd47db9b0", @@ -70,13 +70,13 @@ "https://bcr.bazel.build/modules/rules_cc/0.0.14/MODULE.bazel": "5e343a3aac88b8d7af3b1b6d2093b55c347b8eefc2e7d1442f7a02dc8fea48ac", "https://bcr.bazel.build/modules/rules_cc/0.0.15/MODULE.bazel": "6704c35f7b4a72502ee81f61bf88706b54f06b3cbe5558ac17e2e14666cd5dcc", "https://bcr.bazel.build/modules/rules_cc/0.0.16/MODULE.bazel": "7661303b8fc1b4d7f532e54e9d6565771fea666fbdf839e0a86affcd02defe87", - "https://bcr.bazel.build/modules/rules_cc/0.0.17/MODULE.bazel": "2ae1d8f4238ec67d7185d8861cb0a2cdf4bc608697c331b95bf990e69b62e64a", "https://bcr.bazel.build/modules/rules_cc/0.0.2/MODULE.bazel": "6915987c90970493ab97393024c156ea8fb9f3bea953b2f3ec05c34f19b5695c", "https://bcr.bazel.build/modules/rules_cc/0.0.6/MODULE.bazel": "abf360251023dfe3efcef65ab9d56beefa8394d4176dd29529750e1c57eaa33f", "https://bcr.bazel.build/modules/rules_cc/0.0.8/MODULE.bazel": "964c85c82cfeb6f3855e6a07054fdb159aced38e99a5eecf7bce9d53990afa3e", "https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel": "836e76439f354b89afe6a911a7adf59a6b2518fafb174483ad78a2a2fde7b1c5", "https://bcr.bazel.build/modules/rules_cc/0.1.1/MODULE.bazel": "2f0222a6f229f0bf44cd711dc13c858dad98c62d52bd51d8fc3a764a83125513", - "https://bcr.bazel.build/modules/rules_cc/0.1.1/source.json": "d61627377bd7dd1da4652063e368d9366fc9a73920bfa396798ad92172cf645c", + "https://bcr.bazel.build/modules/rules_cc/0.2.14/MODULE.bazel": "353c99ed148887ee89c54a17d4100ae7e7e436593d104b668476019023b58df8", + "https://bcr.bazel.build/modules/rules_cc/0.2.14/source.json": "55d0a4587c5592fad350f6e698530f4faf0e7dd15e69d43f8d87e220c78bea54", "https://bcr.bazel.build/modules/rules_foreign_cc/0.9.0/MODULE.bazel": "c9e8c682bf75b0e7c704166d79b599f93b72cfca5ad7477df596947891feeef6", "https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/MODULE.bazel": "40c97d1144356f52905566c55811f13b299453a14ac7769dfba2ac38192337a8", "https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/source.json": "c8b1e2c717646f1702290959a3302a178fb639d987ab61d548105019f11e527e", @@ -90,10 +90,8 @@ "https://bcr.bazel.build/modules/rules_java/7.2.0/MODULE.bazel": "06c0334c9be61e6cef2c8c84a7800cef502063269a5af25ceb100b192453d4ab", "https://bcr.bazel.build/modules/rules_java/7.3.2/MODULE.bazel": "50dece891cfdf1741ea230d001aa9c14398062f2b7c066470accace78e412bc2", "https://bcr.bazel.build/modules/rules_java/7.6.1/MODULE.bazel": "2f14b7e8a1aa2f67ae92bc69d1ec0fa8d9f827c4e17ff5e5f02e91caa3b2d0fe", - "https://bcr.bazel.build/modules/rules_java/8.11.0/MODULE.bazel": "c3d280bc5ff1038dcb3bacb95d3f6b83da8dd27bba57820ec89ea4085da767ad", - "https://bcr.bazel.build/modules/rules_java/8.11.0/source.json": "302b52a39259a85aa06ca3addb9787864ca3e03b432a5f964ea68244397e7544", - "https://bcr.bazel.build/modules/rules_java/8.3.2/MODULE.bazel": "7336d5511ad5af0b8615fdc7477535a2e4e723a357b6713af439fe8cf0195017", - "https://bcr.bazel.build/modules/rules_java/8.5.1/MODULE.bazel": "d8a9e38cc5228881f7055a6079f6f7821a073df3744d441978e7a43e20226939", + "https://bcr.bazel.build/modules/rules_java/8.14.0/MODULE.bazel": "717717ed40cc69994596a45aec6ea78135ea434b8402fb91b009b9151dd65615", + "https://bcr.bazel.build/modules/rules_java/8.14.0/source.json": "8a88c4ca9e8759da53cddc88123880565c520503321e2566b4e33d0287a3d4bc", "https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7", "https://bcr.bazel.build/modules/rules_jvm_external/5.1/MODULE.bazel": "33f6f999e03183f7d088c9be518a63467dfd0be94a11d0055fe2d210f89aa909", "https://bcr.bazel.build/modules/rules_jvm_external/5.2/MODULE.bazel": "d9351ba35217ad0de03816ef3ed63f89d411349353077348a45348b096615036", @@ -123,8 +121,7 @@ "https://bcr.bazel.build/modules/rules_python/0.31.0/MODULE.bazel": "93a43dc47ee570e6ec9f5779b2e64c1476a6ce921c48cc9a1678a91dd5f8fd58", "https://bcr.bazel.build/modules/rules_python/0.4.0/MODULE.bazel": "9208ee05fd48bf09ac60ed269791cf17fb343db56c8226a720fbb1cdf467166c", "https://bcr.bazel.build/modules/rules_python/0.40.0/MODULE.bazel": "9d1a3cd88ed7d8e39583d9ffe56ae8a244f67783ae89b60caafc9f5cf318ada7", - "https://bcr.bazel.build/modules/rules_python/1.4.1/MODULE.bazel": "8991ad45bdc25018301d6b7e1d3626afc3c8af8aaf4bc04f23d0b99c938b73a6", - "https://bcr.bazel.build/modules/rules_python/1.4.1/source.json": "8ec8c90c70ccacc4de8ca1b97f599e756fb59173e898ee08b733006650057c07", + "https://bcr.bazel.build/modules/rules_python/0.40.0/source.json": "939d4bd2e3110f27bfb360292986bb79fd8dcefb874358ccd6cdaa7bda029320", "https://bcr.bazel.build/modules/rules_shell/0.2.0/MODULE.bazel": "fda8a652ab3c7d8fee214de05e7a9916d8b28082234e8d2c0094505c5268ed3c", "https://bcr.bazel.build/modules/rules_shell/0.2.0/source.json": "7f27af3c28037d9701487c4744b5448d26537cc66cdef0d8df7ae85411f8de95", "https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8", @@ -132,19 +129,18 @@ "https://bcr.bazel.build/modules/stardoc/0.5.6/MODULE.bazel": "c43dabc564990eeab55e25ed61c07a1aadafe9ece96a4efabb3f8bf9063b71ef", "https://bcr.bazel.build/modules/stardoc/0.7.0/MODULE.bazel": "05e3d6d30c099b6770e97da986c53bd31844d7f13d41412480ea265ac9e8079c", "https://bcr.bazel.build/modules/stardoc/0.7.1/MODULE.bazel": "3548faea4ee5dda5580f9af150e79d0f6aea934fc60c1cc50f4efdd9420759e7", - "https://bcr.bazel.build/modules/stardoc/0.7.2/MODULE.bazel": "fc152419aa2ea0f51c29583fab1e8c99ddefd5b3778421845606ee628629e0e5", - "https://bcr.bazel.build/modules/stardoc/0.7.2/source.json": "58b029e5e901d6802967754adf0a9056747e8176f017cfe3607c0851f4d42216", + "https://bcr.bazel.build/modules/stardoc/0.7.1/source.json": "b6500ffcd7b48cd72c29bb67bcac781e12701cc0d6d55d266a652583cfcdab01", "https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/MODULE.bazel": "7298990c00040a0e2f121f6c32544bab27d4452f80d9ce51349b1a28f3005c43", "https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0", - "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/MODULE.bazel": "af322bc08976524477c79d1e45e241b6efbeb918c497e8840b8ab116802dda79", - "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/source.json": "2be409ac3c7601245958cd4fcdff4288be79ed23bd690b4b951f500d54ee6e7d", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/MODULE.bazel": "eec517b5bbe5492629466e11dae908d043364302283de25581e3eb944326c4ca", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/source.json": "22bc55c47af97246cfc093d0acf683a7869377de362b5d1c552c2c2e16b7a806", "https://bcr.bazel.build/modules/zlib/1.3.1/MODULE.bazel": "751c9940dcfe869f5f7274e1295422a34623555916eb98c174c1e945594bf198" }, "selectedYankedVersions": {}, "moduleExtensions": { "@@rules_kotlin+//src/main/starlark/core/repositories:bzlmod_setup.bzl%rules_kotlin_extensions": { "general": { - "bzlTransitiveDigest": "sFhcgPbDQehmbD1EOXzX4H1q/CD5df8zwG4kp4jbvr8=", + "bzlTransitiveDigest": "OlvsB0HsvxbR8ZN+J9Vf00X/+WVz/Y/5Xrq2LgcVfdo=", "usagesDigest": "QI2z8ZUR+mqtbwsf2fLqYdJAkPOHdOV+tF2yVAUgRzw=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -205,42 +201,6 @@ ] ] } - }, - "@@rules_python+//python/uv:uv.bzl%uv": { - "general": { - "bzlTransitiveDigest": "Xpqjnjzy6zZ90Es9Wa888ZLHhn7IsNGbph/e6qoxzw8=", - "usagesDigest": "4JapxcpS0mL3524k0TZJffAtVyuRjDHZvN9kBRxxF1U=", - "recordedFileInputs": {}, - "recordedDirentsInputs": {}, - "envVariables": {}, - "generatedRepoSpecs": { - "uv": { - "repoRuleId": "@@rules_python+//python/uv/private:uv_toolchains_repo.bzl%uv_toolchains_repo", - "attributes": { - "toolchain_type": "'@@rules_python+//python/uv:uv_toolchain_type'", - "toolchain_names": [ - "none" - ], - "toolchain_implementations": { - "none": "'@@rules_python+//python:none'" - }, - "toolchain_compatible_with": { - "none": [ - "@platforms//:incompatible" - ] - }, - "toolchain_target_settings": {} - } - } - }, - "recordedRepoMappingEntries": [ - [ - "rules_python+", - "platforms", - "platforms" - ] - ] - } } } } diff --git a/example/.bazelrc b/example/.bazelrc new file mode 100644 index 0000000..e69de29 diff --git a/example/MODULE.bazel b/example/MODULE.bazel index 76945b7..fad84df 100644 --- a/example/MODULE.bazel +++ b/example/MODULE.bazel @@ -5,4 +5,4 @@ local_path_override( path = "..", ) -bazel_dep(name = "rules_cc", version = "0.1.1") +bazel_dep(name = "rules_cc", version = "0.2.14") diff --git a/example/MODULE.bazel.lock b/example/MODULE.bazel.lock index 8fa8e09..6524e33 100644 --- a/example/MODULE.bazel.lock +++ b/example/MODULE.bazel.lock @@ -16,8 +16,9 @@ "https://bcr.bazel.build/modules/bazel_features/1.17.0/MODULE.bazel": "039de32d21b816b47bd42c778e0454217e9c9caac4a3cf8e15c7231ee3ddee4d", "https://bcr.bazel.build/modules/bazel_features/1.18.0/MODULE.bazel": "1be0ae2557ab3a72a57aeb31b29be347bcdc5d2b1eb1e70f39e3851a7e97041a", "https://bcr.bazel.build/modules/bazel_features/1.19.0/MODULE.bazel": "59adcdf28230d220f0067b1f435b8537dd033bfff8db21335ef9217919c7fb58", - "https://bcr.bazel.build/modules/bazel_features/1.21.0/MODULE.bazel": "675642261665d8eea09989aa3b8afb5c37627f1be178382c320d1b46afba5e3b", - "https://bcr.bazel.build/modules/bazel_features/1.21.0/source.json": "3e8379efaaef53ce35b7b8ba419df829315a880cb0a030e5bb45c96d6d5ecb5f", + "https://bcr.bazel.build/modules/bazel_features/1.28.0/MODULE.bazel": "4b4200e6cbf8fa335b2c3f43e1d6ef3e240319c33d43d60cc0fbd4b87ece299d", + "https://bcr.bazel.build/modules/bazel_features/1.30.0/MODULE.bazel": "a14b62d05969a293b80257e72e597c2da7f717e1e69fa8b339703ed6731bec87", + "https://bcr.bazel.build/modules/bazel_features/1.30.0/source.json": "b07e17f067fe4f69f90b03b36ef1e08fe0d1f3cac254c1241a1818773e3423bc", "https://bcr.bazel.build/modules/bazel_features/1.4.1/MODULE.bazel": "e45b6bb2350aff3e442ae1111c555e27eac1d915e77775f6fdc4b351b758b5d7", "https://bcr.bazel.build/modules/bazel_features/1.9.1/MODULE.bazel": "8f679097876a9b609ad1f60249c49d68bfab783dd9be012faf9d82547b14815a", "https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8", @@ -54,7 +55,6 @@ "https://bcr.bazel.build/modules/protobuf/27.0/MODULE.bazel": "7873b60be88844a0a1d8f80b9d5d20cfbd8495a689b8763e76c6372998d3f64c", "https://bcr.bazel.build/modules/protobuf/27.1/MODULE.bazel": "703a7b614728bb06647f965264967a8ef1c39e09e8f167b3ca0bb1fd80449c0d", "https://bcr.bazel.build/modules/protobuf/29.0-rc2/MODULE.bazel": "6241d35983510143049943fc0d57937937122baf1b287862f9dc8590fc4c37df", - "https://bcr.bazel.build/modules/protobuf/29.0-rc3/MODULE.bazel": "33c2dfa286578573afc55a7acaea3cada4122b9631007c594bf0729f41c8de92", "https://bcr.bazel.build/modules/protobuf/29.0/MODULE.bazel": "319dc8bf4c679ff87e71b1ccfb5a6e90a6dbc4693501d471f48662ac46d04e4e", "https://bcr.bazel.build/modules/protobuf/29.0/source.json": "b857f93c796750eef95f0d61ee378f3420d00ee1dd38627b27193aa482f4f981", "https://bcr.bazel.build/modules/protobuf/3.19.0/MODULE.bazel": "6b5fbb433f760a99a22b18b6850ed5784ef0e9928a72668b66e4d7ccd47db9b0", @@ -70,13 +70,13 @@ "https://bcr.bazel.build/modules/rules_cc/0.0.14/MODULE.bazel": "5e343a3aac88b8d7af3b1b6d2093b55c347b8eefc2e7d1442f7a02dc8fea48ac", "https://bcr.bazel.build/modules/rules_cc/0.0.15/MODULE.bazel": "6704c35f7b4a72502ee81f61bf88706b54f06b3cbe5558ac17e2e14666cd5dcc", "https://bcr.bazel.build/modules/rules_cc/0.0.16/MODULE.bazel": "7661303b8fc1b4d7f532e54e9d6565771fea666fbdf839e0a86affcd02defe87", - "https://bcr.bazel.build/modules/rules_cc/0.0.17/MODULE.bazel": "2ae1d8f4238ec67d7185d8861cb0a2cdf4bc608697c331b95bf990e69b62e64a", "https://bcr.bazel.build/modules/rules_cc/0.0.2/MODULE.bazel": "6915987c90970493ab97393024c156ea8fb9f3bea953b2f3ec05c34f19b5695c", "https://bcr.bazel.build/modules/rules_cc/0.0.6/MODULE.bazel": "abf360251023dfe3efcef65ab9d56beefa8394d4176dd29529750e1c57eaa33f", "https://bcr.bazel.build/modules/rules_cc/0.0.8/MODULE.bazel": "964c85c82cfeb6f3855e6a07054fdb159aced38e99a5eecf7bce9d53990afa3e", "https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel": "836e76439f354b89afe6a911a7adf59a6b2518fafb174483ad78a2a2fde7b1c5", "https://bcr.bazel.build/modules/rules_cc/0.1.1/MODULE.bazel": "2f0222a6f229f0bf44cd711dc13c858dad98c62d52bd51d8fc3a764a83125513", - "https://bcr.bazel.build/modules/rules_cc/0.1.1/source.json": "d61627377bd7dd1da4652063e368d9366fc9a73920bfa396798ad92172cf645c", + "https://bcr.bazel.build/modules/rules_cc/0.2.14/MODULE.bazel": "353c99ed148887ee89c54a17d4100ae7e7e436593d104b668476019023b58df8", + "https://bcr.bazel.build/modules/rules_cc/0.2.14/source.json": "55d0a4587c5592fad350f6e698530f4faf0e7dd15e69d43f8d87e220c78bea54", "https://bcr.bazel.build/modules/rules_foreign_cc/0.9.0/MODULE.bazel": "c9e8c682bf75b0e7c704166d79b599f93b72cfca5ad7477df596947891feeef6", "https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/MODULE.bazel": "40c97d1144356f52905566c55811f13b299453a14ac7769dfba2ac38192337a8", "https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/source.json": "c8b1e2c717646f1702290959a3302a178fb639d987ab61d548105019f11e527e", @@ -90,10 +90,8 @@ "https://bcr.bazel.build/modules/rules_java/7.2.0/MODULE.bazel": "06c0334c9be61e6cef2c8c84a7800cef502063269a5af25ceb100b192453d4ab", "https://bcr.bazel.build/modules/rules_java/7.3.2/MODULE.bazel": "50dece891cfdf1741ea230d001aa9c14398062f2b7c066470accace78e412bc2", "https://bcr.bazel.build/modules/rules_java/7.6.1/MODULE.bazel": "2f14b7e8a1aa2f67ae92bc69d1ec0fa8d9f827c4e17ff5e5f02e91caa3b2d0fe", - "https://bcr.bazel.build/modules/rules_java/8.11.0/MODULE.bazel": "c3d280bc5ff1038dcb3bacb95d3f6b83da8dd27bba57820ec89ea4085da767ad", - "https://bcr.bazel.build/modules/rules_java/8.11.0/source.json": "302b52a39259a85aa06ca3addb9787864ca3e03b432a5f964ea68244397e7544", - "https://bcr.bazel.build/modules/rules_java/8.3.2/MODULE.bazel": "7336d5511ad5af0b8615fdc7477535a2e4e723a357b6713af439fe8cf0195017", - "https://bcr.bazel.build/modules/rules_java/8.5.1/MODULE.bazel": "d8a9e38cc5228881f7055a6079f6f7821a073df3744d441978e7a43e20226939", + "https://bcr.bazel.build/modules/rules_java/8.14.0/MODULE.bazel": "717717ed40cc69994596a45aec6ea78135ea434b8402fb91b009b9151dd65615", + "https://bcr.bazel.build/modules/rules_java/8.14.0/source.json": "8a88c4ca9e8759da53cddc88123880565c520503321e2566b4e33d0287a3d4bc", "https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7", "https://bcr.bazel.build/modules/rules_jvm_external/5.1/MODULE.bazel": "33f6f999e03183f7d088c9be518a63467dfd0be94a11d0055fe2d210f89aa909", "https://bcr.bazel.build/modules/rules_jvm_external/5.2/MODULE.bazel": "d9351ba35217ad0de03816ef3ed63f89d411349353077348a45348b096615036", @@ -123,8 +121,7 @@ "https://bcr.bazel.build/modules/rules_python/0.31.0/MODULE.bazel": "93a43dc47ee570e6ec9f5779b2e64c1476a6ce921c48cc9a1678a91dd5f8fd58", "https://bcr.bazel.build/modules/rules_python/0.4.0/MODULE.bazel": "9208ee05fd48bf09ac60ed269791cf17fb343db56c8226a720fbb1cdf467166c", "https://bcr.bazel.build/modules/rules_python/0.40.0/MODULE.bazel": "9d1a3cd88ed7d8e39583d9ffe56ae8a244f67783ae89b60caafc9f5cf318ada7", - "https://bcr.bazel.build/modules/rules_python/1.4.1/MODULE.bazel": "8991ad45bdc25018301d6b7e1d3626afc3c8af8aaf4bc04f23d0b99c938b73a6", - "https://bcr.bazel.build/modules/rules_python/1.4.1/source.json": "8ec8c90c70ccacc4de8ca1b97f599e756fb59173e898ee08b733006650057c07", + "https://bcr.bazel.build/modules/rules_python/0.40.0/source.json": "939d4bd2e3110f27bfb360292986bb79fd8dcefb874358ccd6cdaa7bda029320", "https://bcr.bazel.build/modules/rules_shell/0.2.0/MODULE.bazel": "fda8a652ab3c7d8fee214de05e7a9916d8b28082234e8d2c0094505c5268ed3c", "https://bcr.bazel.build/modules/rules_shell/0.2.0/source.json": "7f27af3c28037d9701487c4744b5448d26537cc66cdef0d8df7ae85411f8de95", "https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8", @@ -132,19 +129,18 @@ "https://bcr.bazel.build/modules/stardoc/0.5.6/MODULE.bazel": "c43dabc564990eeab55e25ed61c07a1aadafe9ece96a4efabb3f8bf9063b71ef", "https://bcr.bazel.build/modules/stardoc/0.7.0/MODULE.bazel": "05e3d6d30c099b6770e97da986c53bd31844d7f13d41412480ea265ac9e8079c", "https://bcr.bazel.build/modules/stardoc/0.7.1/MODULE.bazel": "3548faea4ee5dda5580f9af150e79d0f6aea934fc60c1cc50f4efdd9420759e7", - "https://bcr.bazel.build/modules/stardoc/0.7.2/MODULE.bazel": "fc152419aa2ea0f51c29583fab1e8c99ddefd5b3778421845606ee628629e0e5", - "https://bcr.bazel.build/modules/stardoc/0.7.2/source.json": "58b029e5e901d6802967754adf0a9056747e8176f017cfe3607c0851f4d42216", + "https://bcr.bazel.build/modules/stardoc/0.7.1/source.json": "b6500ffcd7b48cd72c29bb67bcac781e12701cc0d6d55d266a652583cfcdab01", "https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/MODULE.bazel": "7298990c00040a0e2f121f6c32544bab27d4452f80d9ce51349b1a28f3005c43", "https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0", - "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/MODULE.bazel": "af322bc08976524477c79d1e45e241b6efbeb918c497e8840b8ab116802dda79", - "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/source.json": "2be409ac3c7601245958cd4fcdff4288be79ed23bd690b4b951f500d54ee6e7d", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/MODULE.bazel": "eec517b5bbe5492629466e11dae908d043364302283de25581e3eb944326c4ca", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/source.json": "22bc55c47af97246cfc093d0acf683a7869377de362b5d1c552c2c2e16b7a806", "https://bcr.bazel.build/modules/zlib/1.3.1/MODULE.bazel": "751c9940dcfe869f5f7274e1295422a34623555916eb98c174c1e945594bf198" }, "selectedYankedVersions": {}, "moduleExtensions": { "@@rules_kotlin+//src/main/starlark/core/repositories:bzlmod_setup.bzl%rules_kotlin_extensions": { "general": { - "bzlTransitiveDigest": "sFhcgPbDQehmbD1EOXzX4H1q/CD5df8zwG4kp4jbvr8=", + "bzlTransitiveDigest": "OlvsB0HsvxbR8ZN+J9Vf00X/+WVz/Y/5Xrq2LgcVfdo=", "usagesDigest": "QI2z8ZUR+mqtbwsf2fLqYdJAkPOHdOV+tF2yVAUgRzw=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -205,42 +201,6 @@ ] ] } - }, - "@@rules_python+//python/uv:uv.bzl%uv": { - "general": { - "bzlTransitiveDigest": "Xpqjnjzy6zZ90Es9Wa888ZLHhn7IsNGbph/e6qoxzw8=", - "usagesDigest": "4JapxcpS0mL3524k0TZJffAtVyuRjDHZvN9kBRxxF1U=", - "recordedFileInputs": {}, - "recordedDirentsInputs": {}, - "envVariables": {}, - "generatedRepoSpecs": { - "uv": { - "repoRuleId": "@@rules_python+//python/uv/private:uv_toolchains_repo.bzl%uv_toolchains_repo", - "attributes": { - "toolchain_type": "'@@rules_python+//python/uv:uv_toolchain_type'", - "toolchain_names": [ - "none" - ], - "toolchain_implementations": { - "none": "'@@rules_python+//python:none'" - }, - "toolchain_compatible_with": { - "none": [ - "@platforms//:incompatible" - ] - }, - "toolchain_target_settings": {} - } - } - }, - "recordedRepoMappingEntries": [ - [ - "rules_python+", - "platforms", - "platforms" - ] - ] - } } } } diff --git a/rules/defs.bzl b/rules/defs.bzl index 33d367e..c4ed9a8 100644 --- a/rules/defs.bzl +++ b/rules/defs.bzl @@ -1,67 +1,70 @@ # rules/defs.bzl -load("@rules_cc//cc:defs.bzl", "cc_library") def _get_stem(filename): """Gets the filename without the last extension. e.g. 'foo.bar.txt' -> 'foo.bar'""" parts = filename.rsplit(".", 1) - if len(parts) > 1 and parts[0]: # Check if there's a non-empty stem + if len(parts) > 1 and parts[0]: return parts[0] - return filename # Return original if no extension or starts with '.' + return filename def _cc_resources_impl(ctx): """Implementation for the cc_resources rule.""" h_files = [] cpp_files = [] - tool_runfiles = ctx.attr._tool[DefaultInfo].default_runfiles.files # Get this once + + # 获取工具的可执行文件对象 + tool_exec = ctx.executable._tool for src_file in ctx.files.srcs: - src_stem = _get_stem(src_file.basename) if ctx.attr.ext_hide else src_file.basename # Use extension if ext is True + # 计算文件名 stem + src_stem = _get_stem(src_file.basename) if ctx.attr.ext_hide else src_file.basename + # 计算输出文件名前缀和变量名 if ctx.attr.out_prefix: - # If out_prefix is "assets", and src_stem is "image", base_name becomes "assets_image" base_name = ctx.attr.out_prefix + "_" + src_stem - # For files, if you want them in a directory: - # file_path_prefix = ctx.attr.out_prefix + "/" + src_stem - # Or for flat structure with prefix: + # 这里定义生成文件的路径前缀 file_path_prefix = ctx.attr.out_prefix + "_" + src_stem else: base_name = src_stem file_path_prefix = src_stem + # 声明输出文件 h_file = ctx.actions.declare_file(file_path_prefix + ".h") cpp_file = ctx.actions.declare_file(file_path_prefix + ".cpp") h_files.append(h_file) cpp_files.append(cpp_file) + # 构建参数 args = ctx.actions.args() args.add("--input", src_file.path) args.add("--output_h", h_file.path) args.add("--output_cpp", cpp_file.path) args.add("--resource_name", base_name) - - # 添加数据类型选择 args.add("--data_type", ctx.attr.data_type) + # 执行 Action ctx.actions.run( - executable = ctx.executable._tool, + executable = tool_exec, arguments = [args], - inputs = depset( - direct = [src_file], - transitive = [tool_runfiles], - ), + inputs = [src_file], + tools = [tool_exec], outputs = [h_file, cpp_file], mnemonic = "CcResourceGen", - progress_message = "Generating C/C++ resources for %s from %s" % (base_name, src_file.short_path), + progress_message = "Generating C/C++ resources: %s -> %s" % (src_file.basename, base_name), ) all_generated_files = h_files + cpp_files return [ + # DefaultInfo 允许你直接将此规则放入 cc_library 的 srcs 中 + # 例如: cc_library(name="res", srcs=[":my_resources"]) DefaultInfo(files = depset(all_generated_files)), - # It's good practice to make output group names distinct + + # OutputGroupInfo 允许你只提取头文件或源文件 + # 例如: filegroup(name="headers", srcs=[":my_resources"], output_group="cc_resource_headers") OutputGroupInfo( cc_resource_headers = depset(h_files), cc_resource_sources = depset(cpp_files), @@ -73,20 +76,20 @@ cc_resources = rule( attrs = { "srcs": attr.label_list( mandatory = True, - allow_files = True, # Allow actual file paths + allow_files = True, doc = "List of input binary files.", ), "out_prefix": attr.string( - doc = "Optional prefix for output file names (e.g., 'my_res') and C variable names. If 'ui' and input is 'icon.png', output is 'ui_icon.h/cpp' and resource name 'ui_icon'.", + doc = "Optional prefix for output file names and C variable names.", ), "ext_hide": attr.bool( default = True, - doc = "Whether to include the extension '.bin' in the output file names.", + doc = "Whether to include the original extension in the output name.", ), "data_type": attr.string( values = ["char", "uchar", "uint"], default = "uchar", - doc = "Data type for the array (char, uchar=unsigned char, uint=unsigned int).", + doc = "Data type for the array (char, uchar, uint).", ), "_tool": attr.label( default = Label("//tools:bin_to_cc"), @@ -95,17 +98,5 @@ cc_resources = rule( doc = "The binary to C/C++ conversion tool.", ), }, - doc = """ - Converts binary files into C/C++ source files. - - This rule takes binary files and generates corresponding C/C++ header and source files - that contain the binary data as arrays. The generated files can be used to embed - resources directly into C/C++ programs. - - Attributes: - srcs: List of input binary files. - out_prefix: Optional prefix for output file names and C variable names. - ext_hide: Whether to exclude the file extension from generated names. - data_type: Data type for the generated array (char, uchar, or uint). - """, + doc = "Converts binary files into C/C++ source files using a host tool.", ) diff --git a/tools/BUILD b/tools/BUILD index 467cbab..af0be24 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -1,10 +1,7 @@ # tools/BUILD -package(default_visibility = ["//visibility:public"]) -py_binary( +cc_binary( name = "bin_to_cc", - srcs = ["bin_to_cc.py"], - # main = "bin_to_cc.py", # Not strictly needed if srcs has only one .py file - # Ensure this tool can be used by rules in other packages - visibility = ["//rules:__pkg__"], + srcs = ["bin_to_cc.cc"], + visibility = ["//visibility:public"], ) diff --git a/tools/bin_to_cc.cc b/tools/bin_to_cc.cc new file mode 100644 index 0000000..a4446a9 --- /dev/null +++ b/tools/bin_to_cc.cc @@ -0,0 +1,243 @@ +#include +#include +#include +#include +#include +#include +#include + +// ----------------------------------------------------------------------------- +// 辅助函数 +// ----------------------------------------------------------------------------- + +std::string get_arg(const std::vector& args, const std::string& key) +{ + for (size_t i = 0; i < args.size(); ++i) + { + if (args[i] == key && i + 1 < args.size()) + { + return args[i + 1]; + } + } + return ""; +} + +std::string get_basename(const std::string& path) +{ + size_t last_slash = path.find_last_of("/\\"); + if (last_slash != std::string::npos) + { + return path.substr(last_slash + 1); + } + return path; +} + +std::string to_upper(std::string s) +{ + std::transform(s.begin(), s.end(), s.begin(), + [](unsigned char c) { return std::toupper(c); }); + return s; +} + +std::string sanitize_for_c_identifier(const std::string& name) +{ + std::string result; + result.reserve(name.size()); + for (char c : name) + { + if (std::isalnum(static_cast(c))) + { + result.push_back(c); + } + else + { + result.push_back('_'); + } + } + if (result.empty()) return "_resource"; + if (std::isdigit(static_cast(result[0]))) return "_" + result; + return result; +} + +// ----------------------------------------------------------------------------- +// 主逻辑 +// ----------------------------------------------------------------------------- + +int main(int argc, char* argv[]) +{ + std::vector args(argv, argv + argc); + + std::string input_path = get_arg(args, "--input"); + std::string output_h_path = get_arg(args, "--output_h"); + std::string output_cpp_path = get_arg(args, "--output_cpp"); + std::string resource_name = get_arg(args, "--resource_name"); + std::string data_type_arg = get_arg(args, "--data_type"); + + if (data_type_arg.empty()) data_type_arg = "uchar"; + + if (input_path.empty() || output_h_path.empty() || output_cpp_path.empty() || resource_name.empty()) + { + std::cerr << "Error: Missing required arguments." << std::endl; + return 1; + } + + std::string c_var_name = sanitize_for_c_identifier(resource_name); + std::string header_basename = get_basename(output_h_path); + std::string include_guard = "__" + to_upper(sanitize_for_c_identifier(resource_name)) + "_H__"; + + // 确定 C 类型 + std::string c_type_str; + if (data_type_arg == "char") c_type_str = "char"; + else if (data_type_arg == "uint") c_type_str = "unsigned int"; + else c_type_str = "unsigned char"; + + // 读取数据 + std::ifstream input(input_path, std::ios::binary); + if (!input) + { + std::cerr << "Error reading input file: " << input_path << std::endl; + return 1; + } + std::vector data( + (std::istreambuf_iterator(input)), + (std::istreambuf_iterator()) + ); + input.close(); + + // ------------------------------------------------------------------------- + // 1. 生成头文件 (.h) + // ------------------------------------------------------------------------- + std::ofstream out_h(output_h_path); + if (!out_h) + { + std::cerr << "Error writing header file." << std::endl; + return 1; + } + + out_h << "// Generated by bin_to_cc (C++11 compliant)\n"; + out_h << "#ifndef " << include_guard << "\n"; + out_h << "#define " << include_guard << "\n\n"; + out_h << "#include \n\n"; + + // C 兼容部分 + out_h << "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n"; + + out_h << "typedef struct {\n"; + out_h << " const char* name;\n"; + out_h << " size_t size;\n"; + out_h << " const " << c_type_str << "* data;\n"; + out_h << "} __ResourceData_" << c_var_name << ";\n\n"; + + out_h << "extern const __ResourceData_" << c_var_name << " " << c_var_name << ";\n\n"; + + out_h << "#ifdef __cplusplus\n} // extern \"C\"\n"; + + // ------------------------------------------------------------ + // C++ 增强部分 (Zero-Copy 包装器) + // ------------------------------------------------------------ + out_h << "\n// C++11 Zero-Copy View Wrapper\n"; + out_h << "#include \n"; + out_h << "#include \n\n"; + + out_h << "struct " << c_var_name << "_view_t {\n"; + out_h << " using value_type = " << c_type_str << ";\n"; + out_h << " using const_iterator = const value_type*;\n\n"; + + // 1. 标准容器接口 (零拷贝) + out_h << " const_iterator begin() const { return " << c_var_name << ".data; }\n"; + out_h << " const_iterator end() const { return " << c_var_name << ".data + " << c_var_name << ".size; }\n"; + out_h << " size_t size() const { return " << c_var_name << ".size; }\n"; + out_h << " const value_type* data() const { return " << c_var_name << ".data; }\n"; + out_h << " const value_type& operator[](size_t i) const { return " << c_var_name << ".data[i]; }\n\n"; + + // 2. 转换为 std::string (如果需要,会拷贝) + out_h << " std::string as_string() const {\n"; + out_h << " return std::string(reinterpret_cast(begin()), size());\n"; + out_h << " }\n\n"; + + // 3. 转换为 std::vector (显式拷贝) + out_h << " std::vector as_vector() const {\n"; + out_h << " return std::vector(begin(), end());\n"; + out_h << " }\n"; + out_h << "};\n\n"; + + // 定义一个静态常量对象,方便直接使用 + // 注意:在头文件中定义 static 对象会导致每个 include 的文件都有一份副本 + // 更好的方式是定义类型,让用户实例化,或者使用 constexpr (如果C++17的话 inline 变量最好) + // 为了兼容性和易用性,这里只定义类型,并提供一个全局引用的宏或者简单的实例化建议 + out_h << "static const " << c_var_name << "_view_t " << c_var_name << "_cpp = {};\n\n"; + + out_h << "#endif // __cplusplus\n\n"; + out_h << "#endif // " << include_guard << "\n"; + out_h.close(); + + // ------------------------------------------------------------------------- + // 2. 生成源文件 (.cpp) + // ------------------------------------------------------------------------- + std::ofstream out_cpp(output_cpp_path); + if (!out_cpp) + { + std::cerr << "Error writing source file." << std::endl; + return 1; + } + + out_cpp << "// Generated by bin_to_cc\n"; + out_cpp << "#include \"" << header_basename << "\"\n\n"; + out_cpp << "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n"; + + out_cpp << "static const " << c_type_str << " " << c_var_name << "_data[] = {"; + out_cpp << std::hex << std::setfill('0'); + + if (data_type_arg == "uint") + { + size_t total_bytes = data.size(); + for (size_t i = 0; i < total_bytes; i += 4) + { + if ((i / 4) % 8 == 0) out_cpp << "\n "; + unsigned int value = 0; + unsigned char b0 = (i < total_bytes) ? data[i] : 0; + unsigned char b1 = (i + 1 < total_bytes) ? data[i + 1] : 0; + unsigned char b2 = (i + 2 < total_bytes) ? data[i + 2] : 0; + unsigned char b3 = (i + 3 < total_bytes) ? data[i + 3] : 0; + value = (static_cast(b3) << 24) | (static_cast(b2) << 16) | + (static_cast(b1) << 8) | (static_cast(b0)); + out_cpp << "0x" << std::setw(8) << value << "u, "; + } + } + else + { + if (data_type_arg == "char") out_cpp << std::dec; + for (size_t i = 0; i < data.size(); ++i) + { + if (i % 12 == 0) out_cpp << "\n "; + if (data_type_arg == "char") out_cpp << static_cast(static_cast(data[i])) << ", "; + else out_cpp << "0x" << std::setw(2) << static_cast(data[i]) << ", "; + } + } + + out_cpp << "\n};\n\n"; + out_cpp << std::dec; + + out_cpp << "const __ResourceData_" << c_var_name << " " << c_var_name << " = {\n"; + out_cpp << " \"" << resource_name << "\",\n"; + out_cpp << " " << data.size() << ",\n"; + out_cpp << " " << c_var_name << "_data\n"; + out_cpp << "};\n\n"; + + out_cpp << "#ifdef __cplusplus\n} // extern \"C\"\n#endif\n"; + out_cpp.close(); + + // ------------------------------------------------------------------------- + // 提示输出 + // ------------------------------------------------------------------------- + std::cout << "// Usage Hint:" << std::endl; + std::cout << "#include \"" << header_basename << "\"" << std::endl; + std::cout << "// 1. C Style:" << std::endl; + std::cout << "extern const __ResourceData_" << c_var_name << " " << c_var_name << ";" << std::endl; + std::cout << "// 2. C++ STL Style (Zero Copy):" << std::endl; + std::cout << "auto& res = " << c_var_name << "_cpp; // Use like std::vector" << std::endl; + std::cout << "// for (auto b : res) { ... }" << std::endl; + std::cout << "// std::vector v = res.as_vector(); // Copied" << std::endl; + + return 0; +} diff --git a/tools/bin_to_cc.py b/tools/bin_to_cc.py deleted file mode 100755 index ebcb7de..0000000 --- a/tools/bin_to_cc.py +++ /dev/null @@ -1,147 +0,0 @@ -# tools/bin_to_cc.py -#!/usr/bin/env python3 -import argparse -import os -import re - -def sanitize_for_c_identifier(name): - """Converts a string to a valid C identifier.""" - # Replace non-alphanumeric characters (and not underscore) with underscore - name = re.sub(r'[^a-zA-Z0-9_]', '_', name) - # If it starts with a digit, prepend an underscore - if name and name[0].isdigit(): - name = '_' + name - # If it's empty after sanitization (e.g. was "---"), provide a default - if not name: - return "_resource" - return name - -def main(): - parser = argparse.ArgumentParser(description="Convert binary file to C/C++ header and source.") - parser.add_argument("--input", required=True, help="Input binary file path.") - parser.add_argument("--output_h", required=True, help="Output header file path (.h).") - parser.add_argument("--output_cpp", required=True, help="Output source file path (.cpp).") - parser.add_argument("--resource_name", required=True, help="Base name for C variable and include guard.") - parser.add_argument("--data_type", choices=['char', 'uchar', 'uint'], default='uchar', - help="Data type for the array (char, uchar=unsigned char, uint=unsigned int). Default: uchar") - args = parser.parse_args() - - c_var_name = sanitize_for_c_identifier(args.resource_name) - header_basename = os.path.basename(args.output_h) # e.g., my_resource.h - include_guard = f"__{sanitize_for_c_identifier(args.resource_name).upper()}_H__" - - # 根据选择的数据类型确定C类型 - c_type_map = { - 'char': 'char', - 'uchar': 'unsigned char', - 'uint': 'unsigned int' - } - data_type = c_type_map[args.data_type] - - try: - with open(args.input, "rb") as f_in: - data = f_in.read() - except IOError as e: - print(f"Error reading input file {args.input}: {e}") - return 1 - - # --- Generate Header File (.h) --- - h_content = f"""\ -// Generated by bin_to_cc.py -#ifndef {include_guard} -#define {include_guard} - -#include // For size_t - -#ifdef __cplusplus -extern "C" {{ -#endif - -typedef struct {{ - const char* name; - size_t size; - const {data_type}* data; -}} __ResourceData_{c_var_name}; - -extern const __ResourceData_{c_var_name} {c_var_name}; - -#ifdef __cplusplus -}} // extern "C" -#endif - -#endif // {include_guard} -""" - try: - os.makedirs(os.path.dirname(args.output_h), exist_ok=True) - # 使用UTF-8编码写入头文件 - with open(args.output_h, "w", encoding='utf-8') as f_h: - f_h.write(h_content) - except IOError as e: - print(f"Error writing header file {args.output_h}: {e}") - return 1 - - # --- Generate Source File (.cpp) --- - cpp_content_parts = [] - cpp_content_parts.append(f"// Generated by bin_to_cc.py\n") - cpp_content_parts.append(f"#include \"{header_basename}\"\n") # Include using basename - cpp_content_parts.append("#include // For size_t, though ResourceData already implies it\n") - - cpp_content_parts.append(f"\n#ifdef __cplusplus\nextern \"C\" {{\n#endif\n") - - cpp_content_parts.append(f"static const {data_type} {c_var_name}_data[] = {{") - - if args.data_type == 'uint': - # 对于unsigned int,每4个字节组成一个整数 - for i in range(0, len(data), 4): - if i % 4 == 0: - cpp_content_parts.append("\n ") - chunk = data[i:i+4] - # 如果最后一个块不足4字节,用0填充 - while len(chunk) < 4: - chunk = chunk + b'\x00' - value = int.from_bytes(chunk, byteorder='little') - cpp_content_parts.append(f"0x{value:08X}u, ") - else: - # 对于char和unsigned char,保持原来的字节模式 - for i, byte in enumerate(data): - if i % 12 == 0: - cpp_content_parts.append("\n ") - if args.data_type == 'char': - cpp_content_parts.append(f"{byte:d}, ") - else: # uchar - cpp_content_parts.append(f"0x{byte:02X}, ") - - # Remove trailing comma and space if data was not empty - if data: - cpp_content_parts[-1] = cpp_content_parts[-1].rstrip(', ') - cpp_content_parts.append("\n};\n\n") - - cpp_content_parts.append(f"const __ResourceData_{c_var_name} {c_var_name} = {{\n") - cpp_content_parts.append(f" \"{args.resource_name}\",\n") - - # 对于uint类型,size需要调整为字节大小 - if args.data_type == 'uint': - array_size = ((len(data) + 3) // 4) * 4 # 向上取整到4的倍数 - cpp_content_parts.append(f" {len(data)}, // 原始字节大小\n") - else: - cpp_content_parts.append(f" sizeof({c_var_name}_data),\n") - - cpp_content_parts.append(f" {c_var_name}_data\n") - cpp_content_parts.append(f"}};\n") - - cpp_content_parts.append(f"\n#ifdef __cplusplus\n}} // extern \"C\"\n#endif\n") - - try: - os.makedirs(os.path.dirname(args.output_cpp), exist_ok=True) - # 使用UTF-8编码写入源文件 - with open(args.output_cpp, "w", encoding='utf-8') as f_cpp: - f_cpp.write(''.join(cpp_content_parts)) - except IOError as e: - print(f"Error writing source file {args.output_cpp}: {e}") - return 1 - - print(f"Successfully generated {args.output_h} and {args.output_cpp} for {args.resource_name}") - return 0 - -if __name__ == "__main__": - exit(main()) \ No newline at end of file