Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starlarkify objc/CompilationAttributes.java #24009

Conversation

keith
Copy link
Member

@keith keith commented Oct 16, 2024

No description provided.

@keith keith requested a review from lberki as a code owner October 16, 2024 17:00
@github-actions github-actions bot added team-Rules-ObjC Issues for Objective-C maintainers awaiting-review PR is awaiting review from an assigned reviewer labels Oct 16, 2024
sdk_frameworks = depset(sdk_frameworks),
weak_sdk_frameworks = depset(weak_sdk_frameworks),
sdk_dylibs = depset(getattr(ctx.attr, "sdk_dylibs", [])),
linkopts = objc_internal.expand_and_tokenize(ctx = ctx, attr = "linkopts", flags = getattr(ctx.attr, "linkopts", [])),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and data weren't covered by tests for expansions, hoping internal google CI helps validate some of this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a close look what the internal Google tests can check here.

There's one more thing I noticed: in ObjcStarlarkInternal.createCompilationAttributes() the call to CompilationAttributes.Builder.addCompileOptionsFromRuleContext() (which sets linkopts, copts, additional_linker_inputs and defines) is only called if the rule has copts.
After digging a bit into the history of this, I currently think that this was not an intended coupling of conditions; the straightforward linear copying that you implemented makes more sense to me.

We can discuss tweaks if any problems surface from this.

"ERROR /workspace/examples/apple_starlark/BUILD:1:13: "
+ "in objc_library rule //examples/apple_starlark:lib:");

assertContainsEvent("sdk_frameworks attribute is disallowed. Use explicit dependencies instead.");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor error text change with fail vs Java. Same behavior and I tried to nearly match it

@keith keith requested a review from pzembrod October 23, 2024 19:29
objc_compilation_context_kwargs["public_hdrs"].extend(compilation_attributes.hdrs.to_list())
objc_compilation_context_kwargs["public_hdrs"].extend(
[artifact for artifact, _ in compilation_attributes.hdrs.to_list()],
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what you are doing here is the corresponding operation to what's happening in CompilationAttributes.Builder.addHeadersFromRuleContext(), right? The picking of the key from the artifact/label pairs returned by CcCommon.getHeaders()?

Unless I'm mistaken, that effectively moves this further down in the chain, changing the content of compilation_attributes.hdrs from artifacts to artifact/label pairs. And since compilation_attributes in compilation_support.bzl is not just passed to objc_common.create_context_and_provider(), but also returned, both by build_common_variables() and register_compile_and_archive_actions_for_j2objc(), so the change doesn't look contained within compilation_support.bzl.

Wouldn't it be better to make the conversion from artifact/label pairs to artifact right when hdrs is initialized in _create_compilation_attributes()? Or am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrm yea good point, pushed that. I assume long term once we can drop this objc specific stuff we'll want the pairs version, but I think you're right it's nicer to not mess with now

@keith keith force-pushed the ks/starlarkify-objc-compilationattributes.java branch from c476d9d to 4154b02 Compare October 24, 2024 23:33
@keith keith requested a review from pzembrod October 24, 2024 23:33
Copy link
Contributor

@pzembrod pzembrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll handle the PR import myself.

sdk_frameworks = depset(sdk_frameworks),
weak_sdk_frameworks = depset(weak_sdk_frameworks),
sdk_dylibs = depset(getattr(ctx.attr, "sdk_dylibs", [])),
linkopts = objc_internal.expand_and_tokenize(ctx = ctx, attr = "linkopts", flags = getattr(ctx.attr, "linkopts", [])),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a close look what the internal Google tests can check here.

There's one more thing I noticed: in ObjcStarlarkInternal.createCompilationAttributes() the call to CompilationAttributes.Builder.addCompileOptionsFromRuleContext() (which sets linkopts, copts, additional_linker_inputs and defines) is only called if the rule has copts.
After digging a bit into the history of this, I currently think that this was not an intended coupling of conditions; the straightforward linear copying that you implemented makes more sense to me.

We can discuss tweaks if any problems surface from this.

@pzembrod pzembrod removed the awaiting-review PR is awaiting review from an assigned reviewer label Oct 25, 2024
copybara-service bot pushed a commit that referenced this pull request Nov 4, 2024
*** Reason for rollback ***

Internal breakages

*** Original change description ***

Starlarkify objc/CompilationAttributes.java

Closes #24009.

PiperOrigin-RevId: 692916945
Change-Id: Idce0820a9e97e049a0568eb031594979de2b8b57
@pzembrod pzembrod reopened this Nov 4, 2024
@github-actions github-actions bot added the awaiting-review PR is awaiting review from an assigned reviewer label Nov 4, 2024
@pzembrod
Copy link
Contributor

pzembrod commented Nov 4, 2024

We had to roll this back as it did break one internal test after all. Will investigate.

@pzembrod
Copy link
Contributor

pzembrod commented Nov 4, 2024

The breaking test was test_linkopts_passed_to_binary() in https://github.com/bazelbuild/rules_apple/blob/master/test/ios_application_test.sh#L168, and the failure message was

in linkopts attribute of ios_application rule //app:app: label '//app:linker_input' in
$(location) expression is not a declared prerequisite of this rule

The immediate cause of the failure was the change in behaviour I mentioned in #24009 (comment), that in the native code linkopts, copts, additional_linker_inputs and defines are only set if the rule has copts whereas in the initial Starlark code they were all set independently of each other. I still believe that to be the right behaviour, but reproducing the native behaviour in Starlark does fix the test so that's what I'll do for now.

I'll investigate this further.

@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Nov 11, 2024
@pzembrod
Copy link
Contributor

In the end, the fix to the broken test was not to reproduce the old native code behaviour where setting of linkopts, additional_linker_inputs and defines depended on the presence of copts, but to add additional_linker_inputs to the declared prerequisites in ObjcStarlarkInternal.expandAndTokenize().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-ObjC Issues for Objective-C maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants