Skip to content

Bare app targets with an Objective-C main.m - #33

Merged
WillyAntunez merged 2 commits into
mainfrom
fix/bare-main-file
Nov 6, 2026
Merged

WillyAntunez merged 2 commits into
mainfrom
fix/bare-main-file

Conversation

@WillyAntunez

Copy link
Copy Markdown
Owner

Bare app targets with an Objective-C main.m

A bare React Native app whose Xcode app target is Objective-C style (AppDelegate.h/AppDelegate.mm plus main.m in the Sources phase, as every React Native template before 0.77 had) stopped inside xtool's SwiftPM build with error: 'ios-xtool': library product 'App' should not contain executable targets (it has 'App'). The app target's sources are copied into Sources/App under their own names, and SwiftPM makes any target with a compiled file named main.<ext> an executable target; xtool needs App to stay a library, because its builder package links the app's entry point from the App library product. Not a release: the notes stay under [Unreleased].

What users get

  • An app target with main.m builds. A C-family main file (main.m, main.mm, main.c, main.cc, main.cpp, main.cxx, in any case) is copied as AppMain.<ext> in the same folder, so it still compiles into the App library and still defines main; UIApplicationMain(…, NSStringFromClass([AppDelegate class])) and #import "AppDelegate.h" keep working. The build prints ℹ <Target>/main.m is compiled as AppMain.m: SwiftPM takes a target with a file named main for an executable, and xtool links the app's entry point from the App library.
  • A name clash is an early error. An app file already named AppMain.<ext>, in any folder, gives the existing duplicate-name error, which now says which file is compiled under that name: Two compiled sources share the name AppMain.m (<Target>/main.m, which is compiled as AppMain.m, and <Target>/AppMain.m). The copy step's own "would both be copied to Sources/App/AppMain.m" check covers the same case.
  • main.swift is refused early, with the remedy. Renaming it would change Swift semantics (top-level code is allowed only in main.swift), so build and doctor --project stop with The app target compiles <Target>/main.swift: … Mark the app delegate class @main (as the React Native template's AppDelegate.swift does), move any other top-level code of main.swift into it, and remove main.swift from the app target.
  • Docs: the Sources section of docs/bare-react-native.md, a troubleshooting entry keyed by the SwiftPM message, and a CHANGELOG line under [Unreleased] → ### Fixed.

Verified

  • The SwiftPM rule, from Sources/PackageLoading/PackageBuilder.swift (Sources.computeModuleKind()): a target not declared with an explicit type is an executable when any compiled source's basename, lowercased, starts with main. and has exactly one dot. Headers are not compiled sources, so main.h does not count; main.test.m and MainView.swift do not count either. rn-xtool matches the same rule (/^main\.[^.]+$/i).
  • Unit tests, written failing first: main.m, main.mm, Main.c and Supporting/main.m are copied as AppMain.* in their folder with the original name absent and the ℹ line printed; an app file named AppMain.m gives the collision error at the copy and at the project read (same folder and another folder); main.swift and Main.swift are refused with the remedy; names that only start with main are left alone.
  • Not verified here: an xtool build of an Objective-C template app. The rename only changes a file name inside Sources/App; the build on a real app is checked separately.

Checks

  • npm test (2379 passed, 6 skipped) and npm run lint pass.
  • npm run scan:private is clean on both commits.

@WillyAntunez
WillyAntunez merged commit d67bc2d into main Nov 6, 2026
1 check passed
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.

1 participant