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

Don't clobber existing CMAKE_CXX_FLAGS_RELEASE #7742

Merged
merged 1 commit into from
Jan 23, 2025
Merged

Conversation

swolchok
Copy link
Contributor

We were likely losing -DNDEBUG. Preserve our current intent to clobber the -O flag in particular, though.

[ghstack-poisoned]
@swolchok
Copy link
Contributor Author

swolchok commented Jan 17, 2025

Copy link

pytorch-bot bot commented Jan 17, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/7742

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 37114d8 with merge base cd0e584 (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 17, 2025
@swolchok swolchok requested review from dbort, digantdesai, malfet and larryliu0820 and removed request for dbort and digantdesai January 17, 2025 22:15
@swolchok swolchok added the release notes: build Changes related to build, including dependency upgrades, build flags, optimizations, etc. label Jan 17, 2025
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
endif()

option(OPTIMIZE_SIZE "Build executorch runtime optimizing for binary size" OFF)
if(OPTIMIZE_SIZE)
# -Os: Optimize for size
set(CMAKE_CXX_FLAGS_RELEASE "-Os ${CMAKE_CXX_FLAGS_RELEASE}")
Copy link
Contributor

Choose a reason for hiding this comment

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

It's pretty typical to put the overridable CMAKE_CXX_FLAGS_RELEASE last so it can override -Os/-O2 if users want to; the new order will always override whatever CMAKE_CXX_FLAGS_RELEASE says. But if that's the intent (like the PR description says), then this seems to do it.

But since this is an unusual pattern, please update the comments on these two cases to clarify that we're intentionally overriding the -O flag so that someone doesn't come back and "fix" it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

someone doesn't come back and "fix" it.

I would be happy for someone to come back and change this further; these two OPTIMIZE_SIZE changes were to preserve existing behavior.

Before: we clobber all of CMAKE_CXX_FLAGS_RELEASE on line 152 above.
After: we only clobber the -O setting with -Os or -O2.

I think our setup is deeply weird and OPTIMIZE_SIZE shouldn't exist; I am just following general good practice by sending an incremental diff that makes a small amount of forward progress rather than attempting to fix everything all at once.

Copy link
Contributor

Choose a reason for hiding this comment

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

After: we only clobber the -O setting with -Os or -O2.

Agreed that it's an improvement. But someone a year from now who's only looking at this line might think "why is -Os last? I'll move it back before the ${CMAKE_CXX_FLAGS_RELEASE}". A comment would help avoid that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm hesitant to enshrine behavior I think is wrong and simply haven't gotten around to fixing yet.

@swolchok swolchok merged commit e000b22 into main Jan 23, 2025
44 of 47 checks passed
@swolchok swolchok deleted the gh/swolchok/141/head branch January 23, 2025 00:07
YIWENX14 pushed a commit that referenced this pull request Jan 28, 2025
We were likely losing -DNDEBUG. Preserve our current intent to clobber the -O flag in particular, though.
zonglinpeng pushed a commit to zonglinpeng/executorch that referenced this pull request Jan 30, 2025
We were likely losing -DNDEBUG. Preserve our current intent to clobber the -O flag in particular, though.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: build Changes related to build, including dependency upgrades, build flags, optimizations, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants