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

NativeModuleSample based on cpp-lib template #991

Merged
merged 13 commits into from
Nov 16, 2024

Conversation

jonthysell
Copy link
Contributor

@jonthysell jonthysell commented Nov 14, 2024

Description

This PR intends to replace the existing sample at NativeModuleSample\cppwinrt with a new NativeModuleSample\cpp-lib, based on the cpp-lib template exposed in RNW 0.76.0.

Features of this new sample includes:

  • Built-in support for supporting both New and Old Architecture app projects
  • Two example apps (one Old Arch, one New Arch) to showcase the E2E works
  • Upgrade from JS to TS
  • Faster native builds thanks to building against the NuGet packages

Why

The old sample is based on the Old Architecture, UWP-based C++ library template. That template is not the target of active development, while the new template is the new standard for RNW >= 0.76.0.

Screenshots

Old Arch Example New Arch Example
image image
Microsoft Reviewers: Open in CodeFlow

@jonthysell jonthysell changed the title [WIP] NativeModuleSample based on cpp-lib template NativeModuleSample based on cpp-lib template Nov 14, 2024
@jonthysell jonthysell marked this pull request as ready for review November 14, 2024 23:34
@jonthysell jonthysell requested review from a team as code owners November 14, 2024 23:34
@jonthysell
Copy link
Contributor Author

jonthysell commented Nov 14, 2024

Note: I will update our native module documentation and delete the old sample in separate PRs.

Copy link
Contributor

@Yajur-Grover Yajur-Grover left a comment

Choose a reason for hiding this comment

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

Quick question: why don't we add the RnwNewArch constants to the old arch templates with the value set to false? Do we want the main upgrade path to be just running the new templates?

@jonthysell
Copy link
Contributor Author

jonthysell commented Nov 16, 2024

Quick question: why don't we add the RnwNewArch constants to the old arch templates with the value set to false? Do we want the main upgrade path to be just running the new templates?

Yes, the intent for the new library templates (currently just cpp-lib, but hopefully with a cs-lib) is to support both Old and New architecture, since that decision is made by the app, not the library.

If the value isn't set (aka every project not 0.76.0+'s cpp-app template), it gets set to false. There's no reason to add the value and modify the old templates unnecessarily (especially for folks who don't regenerate their apps during upgrades).

While the library does appear to set it to true in it's ExperimentalFeatures.props file, that file is only loaded if you open the sln file next to it (aka you just want to build the library by itself, with no app). So if you want to build just the library by itself, but for old arch, you have to change the variable there.

But in this new world where (new) libraries come with a ready to use example app, it's actually a better experience to build the example app so you can actually test that your native module works. And therefore in this example we have two example apps, so you can test both new and old architectures.

@jonthysell jonthysell merged commit 86c591d into microsoft:main Nov 16, 2024
29 checks passed
@jonthysell jonthysell deleted the newsample branch November 16, 2024 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants