Skip to content

Conversation

@noahsmartin
Copy link
Contributor

@noahsmartin noahsmartin commented Jun 5, 2025

Adds asset catalog parsing support. This uses Apple Objective-C APIs, which is why it needs to be run from Swift (or ObjC but we try to use Swift as much as possible)

@noahsmartin noahsmartin force-pushed the assetCatalogParsing branch 7 times, most recently from fd4561a to 112642d Compare June 6, 2025 16:21
@noahsmartin noahsmartin force-pushed the assetCatalogParsing branch from 112642d to ff6040d Compare June 7, 2025 04:20
@noahsmartin noahsmartin marked this pull request as ready for review June 7, 2025 04:24
@szokeasaurusrex
Copy link
Member

szokeasaurusrex commented Jun 10, 2025

Hey @noahsmartin, I still need to review the code changes, but since you modified build.rs, I triggered our "Release Build" CI actions on this PR by also pushing the commit to the release/test branch (the "Release Build" actions only run on branches matching the pattern release/*). The "Release Build" flow is responsible for building the release binaries, so it is important that these actions succeed.

It looks like the build for macOS x86_64 is failing, and the failure appears to be related to the changes introduced in this PR. The Docker image also failed to build, but this failure is unrelated to your change, and I already put up a PR to fix it (#2550).

I would appreciate if you could investigate and try to fix this failure; once you have made the necessary changes, you can rerun the action by pushing to release/test (or another release/* branch of your choosing). 🙏

@szokeasaurusrex
Copy link
Member

I updated this branch with the latest changes from origin/master and the release build is still failing on macOS x86_64 after pushing the updated branch as release/test, which confirms the failure is most likely due to changes in this PR

@noahsmartin noahsmartin force-pushed the assetCatalogParsing branch from a71a846 to 2627c94 Compare June 11, 2025 18:23
Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

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

Hey, thanks for adding this!

I have some comments, mostly regarding project structure and some feedback on Rust idioms. I'll leave the review of the Swift and .h and .m files to someone more familiar with these languages/systems

Copy link
Member

Choose a reason for hiding this comment

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

Likewise, would appreciate if someone more familiar with this code reviews this file and the corresponding .h file. It would be good also to make sure that these are tested somehow

@szokeasaurusrex
Copy link
Member

Also, the release build is still failing on x86_64

@noahsmartin noahsmartin force-pushed the assetCatalogParsing branch 3 times, most recently from e172264 to 28d9d12 Compare June 12, 2025 14:31
@noahsmartin noahsmartin force-pushed the assetCatalogParsing branch from 28d9d12 to 06ac99e Compare June 12, 2025 14:34
@noahsmartin
Copy link
Contributor Author

Thanks @szokeasaurusrex! Just pushed a commit for those comments + fixed the release build

Copy link
Member

@rbro112 rbro112 left a comment

Choose a reason for hiding this comment

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

LGTM on command/rust side. Can't speak to the .h/.m/.swift files as I'm not experienced enough in that realm

@noahsmartin noahsmartin force-pushed the assetCatalogParsing branch from 21da0bd to b15a485 Compare June 12, 2025 18:59
@noahsmartin noahsmartin force-pushed the assetCatalogParsing branch from a530d38 to dd13219 Compare June 17, 2025 21:03
@noahsmartin noahsmartin force-pushed the assetCatalogParsing branch 2 times, most recently from 4b17b79 to 57ca420 Compare June 23, 2025 14:50
@noahsmartin noahsmartin force-pushed the assetCatalogParsing branch from 57ca420 to c91cb3d Compare June 23, 2025 14:51
@@ -0,0 +1,5 @@
#![cfg(target_os = "macos")]
Copy link
Member

Choose a reason for hiding this comment

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

@noahsmartin FYI this is what I meant by using #![cfg(target_os = "macos")] to make the crate empty on non-macOS systems. You'll notice that this allows us to remove the other #[cfg(target_os = "macos"] directives that were scattered around here

"--scratch-path",
&format!("{out_dir}/swift-scratch"),
"--triple",
&format!("{arch}-apple-macosx11"),
Copy link
Member

Choose a reason for hiding this comment

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

Does this break compatibility with macos versions below 11?

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 ended up being able to remove this entirely. Based on https://doc.rust-lang.org/cargo/commands/cargo-build.html#compilation-options it sounds like the supported macOS versions are determined from the machine that it builds from?

Copy link
Member

Choose a reason for hiding this comment

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

@noahsmartin I'm confused – why are the Rust docs at all relevant here? These arguments are being passed to the swift command

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rust also has a triple argument which I thought is how it is determined what OS the rust code is compatible with

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 confirmed the current CLI (downloaded from GitHub releases) supports macOS 11+

noahmartin@L4F00WF7KT sentry-cli % otool -l /Users/noahmartin/Downloads/sentry-cli-Darwin-arm64  | grep LC_BUILD_VERSION -A 5
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 11.0
      sdk 14.5
   ntools 1

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but this is the triple you are passing to the swift compiler

Copy link
Member

Choose a reason for hiding this comment

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

Also, you are checking the arm64 build there. The first ARM based Mac was released running macOS 11, so perhaps that explains the minimum version.

I'd be interested in seeing the min version for the x86_64 version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, it was 10.12, just updated the PR to build for this minimum:

Load command 9
      cmd LC_VERSION_MIN_MACOSX
  cmdsize 16
  version 10.12
      sdk 15.5

@szokeasaurusrex
Copy link
Member

I think this is super close to being ready, @noahsmartin! Just a few more small items :)

Please pull my minor changes before changing anything, I fixed something in Cargo.toml

@noahsmartin noahsmartin force-pushed the assetCatalogParsing branch from 87743fc to 0f70e30 Compare June 23, 2025 16:27
@szokeasaurusrex
Copy link
Member

@noahsmartin the x86_64 release build for macOS is failing again :(

@noahsmartin noahsmartin force-pushed the assetCatalogParsing branch from d852375 to dfc8cc1 Compare June 24, 2025 16:47
Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

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

Looks good, thank you for bearing with me here! I would also like to get a review from another Rust engineer before we merge this, however.

let c_string = CString::new(path.as_ref().as_os_str().as_bytes())?;
let string_ptr = c_string.as_ptr();
unsafe {
// The string pointed to is immutable, in Swift we cannot change it.
Copy link
Member

Choose a reason for hiding this comment

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

@noahsmartin just to confirm here: Is the Swift code itself respecting the string's immutability?

Although it is true that the string is immutable in Rust, once you obtain a raw pointer to it, and once the Swift code has access to that raw pointer, the Rust compiler can no longer enforce the immutability invariant. But, the way your comment is written makes it sound like you are relying on the Rust compiler to be ensuring immutability here. To ensure memory safety, therefore, it is essential that the Swift code does not (and ideally cannot, via Swift's type system) mutate anything the pointer is pointing to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is also immutable in Swift, the type in swift is UnsafePointer<CChar> which is immutable, to mutate it the type would have needed to be UnsafeMutablePointer<CChar>

Copy link
Member

Choose a reason for hiding this comment

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

Awesome, thanks! If you could update the comment to clarify that the pointer is immutable in Swift, that would be nice

@szokeasaurusrex szokeasaurusrex requested a review from Dav1dde June 25, 2025 10:35
@noahsmartin noahsmartin merged commit de69b5e into master Jun 25, 2025
54 checks passed
@noahsmartin noahsmartin deleted the assetCatalogParsing branch June 25, 2025 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants