Doing random post build things on IOS artifacts
Let's say I have a normal ios_static_framework rule. The following works as expected:
bazel build --apple_platform_type=ios --ios_multi_cpus=arm64,armv7 :my_static_framework
Now I want to do something on the produced framework zip file by means of a sh_binary rule:
sh_binary(
name="do_things_on_framework",
data = [ ":my_static_framework" ],
srcs = [ "my_script.sh" ],
)
Now I try:
bazel run --apple_platform_type=ios --ios_multi_cpus=arm64,armv7 :do_things_on_framework
And it results in spectacular misbehavior: the script is executed as if it had no dependencies and runfiles manifest has no entry for "my_static_framework". In fact, bazel ignores the platform settings outright.
What is the correct approach to add post-build steps to ios_*_framework or ios_application rules? Those are very important, yet rules_apple appears to break the usual Bazel logic somehow.
Do you want to use the artifact to build something else or do you want to post-process the artifact? If it's the latter, you can pass your script to the ipa_post_processor attribute.
In essence, I want it to build something else (and do other evil things as part of CICD flow).
Upon additional experimentation, I have established, that something like this triggers the build as expected:
sh_binary(
name="do_things_on_framework",
data = [ ":my_static_framework.apple_static_library" ],
srcs = [ "my_script.sh" ],
)
So the first rule in the relevant macro does the right thing, it's the bundling rule which does something wrong. But it should be relatively easy to fix it, from the look of it.
I see what you mean. Yes, the rules in those macros use implicit outputs instead of attr.output so you can't use label to refer to the output.
By the way, the .apple_static_library file is not the final output (of the final rule) of the ios_static_framework macro. The final output is a zip file:
sh_binary(
name = "do_things_on_framework",
data = [ ":my_static_framework.zip" ],
srcs = [ "my_script.sh" ],
)
Thank you, I will try that. This setup is rather not obvious. :-)
This example in tensorflow might be useful for you https://github.com/tensorflow/tensorflow/blob/3b9214e1b049743abf76c16ed9b781f8c59c25a7/tensorflow/lite/ios/ios.bzl#L26-L80
Yes, it works for me now.
Don't you think this point should at least be mentioned in the docs?
Right now the docs merely say:
The .ipa file and other outputs are located in the $WORKSPACE/bazel-bin/ios-app directory.
It's nice and all, but building a framework/app is seldom the very last step in modern builds.
Which part are you thinking about documenting specifically? Happy to accept PRs that improve the docs, the difference between foo and foo.zip surprises me as well, that might be worth debugging further