rules_xcodeproj icon indicating copy to clipboard operation
rules_xcodeproj copied to clipboard

Feature Request: collect custom source files

Open xinzhengzhang opened this issue 1 year ago • 4 comments

Hello, I'm trying to use kotlin multiplatform recently and I have implemented a rule for compiling kotlin source files into static_framework so they can be integrated into iOS ecosystem. This is my current implementation of pseudocode.

load("@build_bazel_rules_apple//apple:apple.bzl", "apple_static_framework_import")

# Macro
def kt_native_ios_static_framework(
        name,
        export_klibs,
        module_name = None,
        **attrs):
    generator_name = name + "_generator"

    _kt_native_ios_static_framework_generator(
        name = generator_name,
        export_klibs = export_klibs,
        module_name = module_name,
    )

    apple_static_framework_import(
        name = name,
        framework_imports = [":{}".format(generator_name)],
        **attrs
    )

I currently have an implementation of a gradle project generator similar to xcodeproj for daily development of Kotlin Multiplatform, but for iOS engineers although Xcode cannot syntax highlighting and code prompts, I still hope to put the source files of kotlin in xcode so that at least breakpoint and print variables can be used when Debug. I read the documentation and it seems that there is no particularly suitable place for me to aspect all dependencies to find the corresponding kotlin source code and put it in the xcode project as extra files. Is there any suggestions for this?

xinzhengzhang avatar Aug 16 '23 05:08 xinzhengzhang

For minimal changes, I currently add such a patch to achieve it.

diff --git a/xcodeproj/internal/automatic_target_info.bzl b/xcodeproj/internal/automatic_target_info.bzl
index 4b72b8fb..8700d096 100644
--- a/xcodeproj/internal/automatic_target_info.bzl
+++ b/xcodeproj/internal/automatic_target_info.bzl
@@ -218,6 +218,10 @@ def calculate_automatic_target_info(ctx, build_mode, target):
         should_generate_target = False
         collect_uncategorized_files = False
         xcode_targets = _DEPS_ONLY_XCODE_TARGETS
+    elif rule_kind == "_kt_native_library":
+        should_generate_target = False
+        xcode_targets = _EMPTY_XCODE_TARGETS
+        srcs = _SRCS_ATTRS
     else:
         xcode_targets = _DEFAULT_XCODE_TARGETS[this_target_type]

xinzhengzhang avatar Aug 18 '23 09:08 xinzhengzhang

So the supported way is for custom rules to return an XcodeProjAutomaticTargetProcessingInfo provider instance, which would allow setting srcs and such like you did there. This is another ruleset though, so your change makes more sense. I think longer term we should allow setting a dictionary on xcodeproj itself for custom sources collection (per this feature request).

For now I would accept a PR with your change above as a minor improvement for now.

brentleyjones avatar Aug 18 '23 13:08 brentleyjones

As rules_kotlinin the community does not support native and has many missing major features downstream, such as:

  1. Support for Gradle module in rules_jvm_external
  2. Support for Bzlmod

And I have only partially implemented the spec to meet the usage scenario, it has not reached the level of being open sourced. I think it is more reasonable to maintain it locally with my own patch for now. Once upstream applies these capabilities, or I implement another version of kt-native, it will be more suitable to merge it upstream.

xinzhengzhang avatar Aug 19 '23 18:08 xinzhengzhang

:+1:. Just be sure to create a release archive with bazel build //distribution:release, and use that instead of depending on a source version of rules_xcodeproj. In the future this will be even more required, as the ruleset assumes that you are using precompiled binaries.

brentleyjones avatar Aug 19 '23 19:08 brentleyjones