Skip to content

Commit

Permalink
[0.76] Add RnwNewArch property and RNW_NEW_ARCH constants when buildi…
Browse files Browse the repository at this point in the history
…ng projects for the new architecture (#14096)

* [0.76] Add RnwNewArch property and RNW_NEW_ARCH constants when building projects for the new architecture

THis PR backports #14042 to 0.76.

## Description

This PR adds a `RnwNewArch` MSBuild property and `RNW_NEW_ARCH` build-time constant / pre-processor directive for use by external (module) devs. This PR also updates `@react-native-windows/codegen` to use the directive when appropriate, and also applies those changes to `sample-custom-component`.

The expectation is that external devs now use these new properties and directives instead of the previously exposed `UseFabric`, `UseHermes` and/or `UseWinUI3` props. All logic expecting external developers to manually set those props has been removed and replaced with more robust checking that keys off `RnwNewArch` and throws warnings or errors if the other props aren't set correctly.

In addition, this PR adds further checks to make sure external projects load the WindowsSDK props sheet, followed by the appropriate RNW props and then the RNW targets. Failure to load these import properly would always risk putting the project in a broken state, now we at least tell people what they're missing.

Note: Old arch devs will still be able to toggle `UseHermes`.

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

### Why
We don't want end-users to have access to conditionally build their code for the new or old architectures, without having to use/replicate the current complicated un-scoped directives we use internally.

Closes #13929

### What
See above.

## Screenshots
N/A

## Testing
Verified the flag exists and builds for the sample-custom-component. Also verified that new projects build properly.

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

Add RnwNewArch property and RNW_NEW_ARCH constants when building projects for the new architecture
  • Loading branch information
jonthysell authored Nov 7, 2024
1 parent 2bb47d5 commit 28e050f
Show file tree
Hide file tree
Showing 72 changed files with 654 additions and 184 deletions.
6 changes: 0 additions & 6 deletions .ado/jobs/cli-init-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,6 @@ jobs:
platform: ${{ parameters.platform }}
configuration: ${{ parameters.configuration }}
buildEnvironment: ${{ parameters.buildEnvironment }}

- task: CmdLine@2
displayName: Create npm directory
name: createNpmDirectory
inputs:
script: mkdir %APPDATA%\npm

- template: ../templates/react-native-init-windows.yml
parameters:
Expand Down
2 changes: 2 additions & 0 deletions .ado/jobs/playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ jobs:
msbuildArgs:
/p:PackageCertificateKeyFile=$(Build.SourcesDirectory)\EncodedKey.pfx
/p:PackageCertificatePassword=${{ parameters.certificatePassword }}
${{if eq(matrix.SolutionFile, 'Playground-Composition.sln')}}:
parallelBuild: false # required to workaround issue #13599

- ${{if and(false, endsWith(matrix.Name, 'Universal'), eq(matrix.BuildConfiguration, 'Debug')) }}: # Disabled as debugging doesn't work,remove false after issue is resolved, see https://github.com/microsoft/react-native-windows/issues/13543
# Execute debug feature tests (skip this step for the Win32 Playground app and for release builds)
Expand Down
3 changes: 0 additions & 3 deletions .ado/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ extends:

- template: .ado/templates/run-compliance-prebuild.yml@self

- script: if not exist %USERPROFILE%\AppData\Roaming\npm (mkdir %USERPROFILE%\AppData\Roaming\npm)
displayName: Fix missing npm config

- pwsh: |
npx beachball check --verbose 2>&1 | Tee-Object -Variable beachballOutput
$beachballErrors = $beachballOutput | Where-Object { $_ -match "ERROR: *"}
Expand Down
2 changes: 1 addition & 1 deletion .ado/templates/enable-fabric-experimental-feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ steps:
$nsm.AddNamespace('ns', $experimentalFeatures.DocumentElement.NamespaceURI)
$xmlNode = $experimentalFeatures.CreateElement("PropertyGroup");
$xmlNode.InnerXml = "<UseFabric>true</UseFabric><UseWinUI3>true</UseWinUI3>"
$xmlNode.InnerXml = "<RnwNewArch>true</RnwNewArch><UseFabric>true</UseFabric><UseWinUI3>true</UseWinUI3>"
$experimentalFeatures.DocumentElement.AppendChild($xmlNode);
Expand Down
3 changes: 2 additions & 1 deletion .ado/templates/msbuild-sln.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ parameters:
msbuildArguments: ''
warnAsError: true
oneESMode: false
parallelBuild: true

steps:
- powershell: |
Expand All @@ -36,7 +37,7 @@ steps:
platform: ${{ parameters.buildPlatform }}
configuration: ${{ parameters.buildConfiguration }}
clean: false # Optional
maximumCpuCount: true
maximumCpuCount: ${{parameters.parallelBuild}}
restoreNugetPackages: false # Optional
createLogFile: true
logFileVerbosity: detailed
Expand Down
4 changes: 4 additions & 0 deletions .ado/templates/prepare-js-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ steps:
inputs:
versionSpec: '18.x'

- script: if not exist %APPDATA%\npm (mkdir %APPDATA%\npm)
displayName: Ensure npm directory for npx commands
condition: eq(variables['Agent.OS'], 'Windows_NT')

- template: yarn-install.yml
parameters:
agentImage: ${{ parameters.agentImage }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "[0.76] Add RnwNewArch property and RNW_NEW_ARCH constants when building projects for the new architecture",
"packageName": "@react-native-windows/automation-channel",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "[0.76] Add RnwNewArch property and RNW_NEW_ARCH constants when building projects for the new architecture",
"packageName": "@react-native-windows/codegen",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "[0.76] Add RnwNewArch property and RNW_NEW_ARCH constants when building projects for the new architecture",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"jsonrpc-lite": "^2.2.0"
},
"devDependencies": {
"@react-native-community/cli": "15.0.0-alpha.2",
"@rnw-scripts/eslint-config": "1.2.27",
"@rnw-scripts/just-task": "2.3.44",
"@rnw-scripts/ts-config": "2.0.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<Import Project="PropertySheet.props" />
</ImportGroup>
<ImportGroup Label="ReactNativeWindowsPropertySheets">
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\external\Microsoft.ReactNative.Uwp.CppLib.props" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props')" />
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\external\Microsoft.ReactNative.CppLib.props" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props')" />
<!-- Added since we build this project with Paper/Fabric. -->
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\NuGet.LockFile.props" />
</ImportGroup>
Expand Down Expand Up @@ -143,13 +143,13 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ReactNativeWindowsTargets">
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets')" />
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets')" />
</ImportGroup>
<Target Name="EnsureReactNativeWindowsTargets" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references targets in your node_modules\react-native-windows folder that are missing. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props'))" />
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets'))" />
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props'))" />
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets'))" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
"version": 1,
"dependencies": {
"native,Version=v0.0": {
"boost": {
"type": "Direct",
"requested": "[1.83.0, )",
"resolved": "1.83.0",
"contentHash": "cy53VNMzysEMvhBixDe8ujPk67Fcj3v6FPHQnH91NYJNLHpc6jxa2xq9ruCaaJjE4M3YrGSHDi4uUSTGBWw6EQ=="
},
"Microsoft.VCRTForwarders.140": {
"type": "Direct",
"requested": "[1.0.2-rc, )",
"resolved": "1.0.2-rc",
"contentHash": "/r+sjtEeCIGyDhobIZ5hSmYhC/dSyGZxf1SxYJpElUhB0LMCktOMFs9gXrauXypIFECpVynNyVjAmJt6hjJ5oQ=="
},
"Microsoft.Windows.CppWinRT": {
"type": "Direct",
"requested": "[2.0.230706.1, )",
Expand All @@ -18,11 +30,6 @@
"Microsoft.Windows.SDK.BuildTools": "10.0.22621.756"
}
},
"boost": {
"type": "Transitive",
"resolved": "1.83.0",
"contentHash": "cy53VNMzysEMvhBixDe8ujPk67Fcj3v6FPHQnH91NYJNLHpc6jxa2xq9ruCaaJjE4M3YrGSHDi4uUSTGBWw6EQ=="
},
"Microsoft.Build.Tasks.Git": {
"type": "Transitive",
"resolved": "1.1.1",
Expand Down Expand Up @@ -94,6 +101,12 @@
}
},
"native,Version=v0.0/win10-arm": {
"Microsoft.VCRTForwarders.140": {
"type": "Direct",
"requested": "[1.0.2-rc, )",
"resolved": "1.0.2-rc",
"contentHash": "/r+sjtEeCIGyDhobIZ5hSmYhC/dSyGZxf1SxYJpElUhB0LMCktOMFs9gXrauXypIFECpVynNyVjAmJt6hjJ5oQ=="
},
"Microsoft.WindowsAppSDK": {
"type": "Direct",
"requested": "[1.6.240923002, )",
Expand All @@ -111,6 +124,12 @@
}
},
"native,Version=v0.0/win10-arm-aot": {
"Microsoft.VCRTForwarders.140": {
"type": "Direct",
"requested": "[1.0.2-rc, )",
"resolved": "1.0.2-rc",
"contentHash": "/r+sjtEeCIGyDhobIZ5hSmYhC/dSyGZxf1SxYJpElUhB0LMCktOMFs9gXrauXypIFECpVynNyVjAmJt6hjJ5oQ=="
},
"Microsoft.WindowsAppSDK": {
"type": "Direct",
"requested": "[1.6.240923002, )",
Expand All @@ -128,6 +147,12 @@
}
},
"native,Version=v0.0/win10-arm64-aot": {
"Microsoft.VCRTForwarders.140": {
"type": "Direct",
"requested": "[1.0.2-rc, )",
"resolved": "1.0.2-rc",
"contentHash": "/r+sjtEeCIGyDhobIZ5hSmYhC/dSyGZxf1SxYJpElUhB0LMCktOMFs9gXrauXypIFECpVynNyVjAmJt6hjJ5oQ=="
},
"Microsoft.WindowsAppSDK": {
"type": "Direct",
"requested": "[1.6.240923002, )",
Expand All @@ -145,6 +170,12 @@
}
},
"native,Version=v0.0/win10-x64": {
"Microsoft.VCRTForwarders.140": {
"type": "Direct",
"requested": "[1.0.2-rc, )",
"resolved": "1.0.2-rc",
"contentHash": "/r+sjtEeCIGyDhobIZ5hSmYhC/dSyGZxf1SxYJpElUhB0LMCktOMFs9gXrauXypIFECpVynNyVjAmJt6hjJ5oQ=="
},
"Microsoft.WindowsAppSDK": {
"type": "Direct",
"requested": "[1.6.240923002, )",
Expand All @@ -162,6 +193,12 @@
}
},
"native,Version=v0.0/win10-x64-aot": {
"Microsoft.VCRTForwarders.140": {
"type": "Direct",
"requested": "[1.0.2-rc, )",
"resolved": "1.0.2-rc",
"contentHash": "/r+sjtEeCIGyDhobIZ5hSmYhC/dSyGZxf1SxYJpElUhB0LMCktOMFs9gXrauXypIFECpVynNyVjAmJt6hjJ5oQ=="
},
"Microsoft.WindowsAppSDK": {
"type": "Direct",
"requested": "[1.6.240923002, )",
Expand All @@ -179,6 +216,12 @@
}
},
"native,Version=v0.0/win10-x86": {
"Microsoft.VCRTForwarders.140": {
"type": "Direct",
"requested": "[1.0.2-rc, )",
"resolved": "1.0.2-rc",
"contentHash": "/r+sjtEeCIGyDhobIZ5hSmYhC/dSyGZxf1SxYJpElUhB0LMCktOMFs9gXrauXypIFECpVynNyVjAmJt6hjJ5oQ=="
},
"Microsoft.WindowsAppSDK": {
"type": "Direct",
"requested": "[1.6.240923002, )",
Expand All @@ -196,6 +239,12 @@
}
},
"native,Version=v0.0/win10-x86-aot": {
"Microsoft.VCRTForwarders.140": {
"type": "Direct",
"requested": "[1.0.2-rc, )",
"resolved": "1.0.2-rc",
"contentHash": "/r+sjtEeCIGyDhobIZ5hSmYhC/dSyGZxf1SxYJpElUhB0LMCktOMFs9gXrauXypIFECpVynNyVjAmJt6hjJ5oQ=="
},
"Microsoft.WindowsAppSDK": {
"type": "Direct",
"requested": "[1.6.240923002, )",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup Label="Microsoft.ReactNative Experimental Features">
<RnwNewArch>false</RnwNewArch>
<UseExperimentalNuget>false</UseExperimentalNuget>

<ReactExperimentalFeaturesSet>true</ReactExperimentalFeaturesSet>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ const headerTemplate = `/*
*/
#pragma once
#include <JSValueComposition.h>
#include <NativeModules.h>
#ifdef RNW_NEW_ARCH
#include <JSValueComposition.h>
#include <winrt/Microsoft.ReactNative.Composition.h>
#include <winrt/Microsoft.UI.Composition.h>`;
#include <winrt/Microsoft.UI.Composition.h>
#endif // #ifdef RNW_NEW_ARCH`;

const propsTemplate = `REACT_STRUCT(::_PROPS_NAME_::)
struct ::_PROPS_NAME_:: : winrt::implements<::_PROPS_NAME_::, winrt::Microsoft::ReactNative::IComponentProps> {
Expand Down Expand Up @@ -220,6 +224,8 @@ void Register::_COMPONENT_NAME_::NativeComponent(
const fileTemplate = `
${headerTemplate}
#ifdef RNW_NEW_ARCH
namespace ::_NAMESPACE_:: {
::_COMPONENT_PROP_OBJECT_TYPES_::
Expand All @@ -231,6 +237,8 @@ namespace ::_NAMESPACE_:: {
::_COMPONENT_REGISTRATION_::
} // namespace ::_NAMESPACE_::
#endif // #ifdef RNW_NEW_ARCH
`;

function capitalizeFirstLetter(s: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup Label="Microsoft.ReactNative Experimental Features">
<UseFabric>true</UseFabric>
<UseWinUI3>true</UseWinUI3>
<RnwNewArch>true</RnwNewArch>
<UseExperimentalNuget>false</UseExperimentalNuget>

<ReactExperimentalFeaturesSet>true</ReactExperimentalFeaturesSet>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
"type": "Project",
"dependencies": {
"Microsoft.ReactNative": "[1.0.0, )",
"Microsoft.WindowsAppSDK": "[1.6.240923002, )"
"Microsoft.VCRTForwarders.140": "[1.0.2-rc, )",
"Microsoft.WindowsAppSDK": "[1.6.240923002, )",
"boost": "[1.83.0, )"
}
},
"common": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions Condition="'$(UseFabric)'=='true'">USE_FABRIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<PropertyGroup Label="UserMacros" />
<ItemGroup>
<ClInclude Include="RNTesterApp-Fabric.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
"type": "Project",
"dependencies": {
"Microsoft.ReactNative": "[1.0.0, )",
"Microsoft.WindowsAppSDK": "[1.6.240923002, )"
"Microsoft.VCRTForwarders.140": "[1.0.2-rc, )",
"Microsoft.WindowsAppSDK": "[1.6.240923002, )",
"boost": "[1.83.0, )"
}
},
"common": {
Expand Down
Loading

0 comments on commit 28e050f

Please sign in to comment.