Skip to content

Create new arch module template: cpp-lib#12481

Merged
jonthysell merged 11 commits intomicrosoft:mainfrom
jonthysell:cpplib
Jan 18, 2024
Merged

Create new arch module template: cpp-lib#12481
jonthysell merged 11 commits intomicrosoft:mainfrom
jonthysell:cpplib

Conversation

@jonthysell
Copy link
Copy Markdown
Contributor

@jonthysell jonthysell commented Dec 1, 2023

Description

Adds a new cpp-lib template designed to be applied on top of the new projects created by the (now recommended) create-react-native-library script. Also updates the cpp-app template to be able to autolink and run these new libraries.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Why

Devs need to add windows support to native modules in a way which can be consumed by the new arch RNW apps (i.e. the cpp-app template).

Resolves #12480

What

Create a new cpp-lib template which can be applied on top of the template created by npx create-react-native-library, adding Windows support for a turbo module. It will also automatically apply the cpp-app template to the example project if it exists.

Screenshots

image

Testing

Verified the new template could be applied to a fresh library created by create-react-native-library and that example app autolinks, builds, and runs correctly.

Changelog

Should this change be included in the release notes: yes

Created a new arch module template: cpp-lib

Microsoft Reviewers: Open in CodeFlow

## Description

Adds a new `cpp-lib` template designed to be applied on top of the new projects created by the (now recommended) `create-react-native-library` script.

### Type of Change
- New feature (non-breaking change which adds functionality)
- This change requires a documentation update

### Why
Devs need to add windows support to native modules in a way which can be consumed by the new arch RNW apps (i.e. the `cpp-app` template).

Resolves #12480

### What
Create a new `cpp-lib` template which can be applied on top of the template created by `npx  create-react-native-library`, adding Windows support for a turbo module. It will also automatically apply the `cpp-app` template to the example project if it exists.

## Screenshots
<img width="441" alt="image" src="https://github.com/microsoft/react-native-windows/assets/10852185/f5f31727-a233-419c-8afe-ad91f797abb2">

## Testing
Verified the new template could be applied to a fresh library created by `create-react-native-library` and that example app autolinks, builds, and runs correctly.

## Changelog
Should this change be included in the release notes: yes

Created a new arch module template: cpp-lib
@jonthysell jonthysell marked this pull request as ready for review December 5, 2023 23:06
@jonthysell jonthysell requested review from a team as code owners December 5, 2023 23:06
Comment thread vnext/templates/cpp-lib/example/metro.config.js Outdated
Comment thread vnext/templates/cpp-lib/example/metro.config.js
Comment thread vnext/templates/cpp-lib/windows/MyLib/pch.h Outdated
const cmd = isYarn ? 'yarn' : 'npm i';

try {
await exec(cmd, options?.logging ? {stdio: 'inherit'} : {});
Copy link
Copy Markdown
Contributor Author

@jonthysell jonthysell Jan 16, 2024

Choose a reason for hiding this comment

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

This works for cpp-app both locally and in CI. This also works for cpp-lib locally. But for some reason (probably to do with the lib template using yarn 2+) this fails in CI. So I've added this here to notify the user they need to run it locally if it happens to fail, but I'll need to follow up and see if I can fix this in CI.

@jonthysell jonthysell added the New Architecture Broad category for issues that apply to the RN "new" architecture of Turbo Modules + Fabric label Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Fabric Support Facebook Fabric Area: Native Modules New Architecture Broad category for issues that apply to the RN "new" architecture of Turbo Modules + Fabric

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Create a "new-lib" template, defaulting to C++, Fabric, Hermes, NuGet-based, Win32 lib

4 participants