Skip to content

Commit 9cf1383

Browse files
chrfalchfacebook-github-bot
authored andcommitted
fixed inclusion of resources in swift package (#50050)
Summary: We had some issues with the Swift package build step where we saw an error message when we included resources and couldn't find out why this was happening. After systematically going through the generated swift package file and looking for a reason I found a mistake. When we generate the Package.swift file we pass all compilerFlags from the configuration of the target to both cpp/c flags - which in the case of the folly target ends up being passed to the dependency scanner which isn't too happy about this c++ flag. The solution was to split `compilerFlags` into `cCompilerFlags` and `cxxCompilerFlags`. This commit fixes this by: - split `compilerFlags` into `cCompilerFlags` and `cxxCompilerFlags`. - Updated configuration with correct settings - Updated Package.swift generation to use these new flags - Fixed issue with the copy bundles step that didn't copy the directory in some cases. ## Changelog: [INTERNAL] - Fixed processing resources in the generated swift package for the RN Dependencies/prebuild ## Test-plan Test by prebuilding RNDependencies, include the XCFramework in a new app and try to load resource bundles: ```obj-c - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { std::string input = "3.1416 xyz "; double_conversion::DoubleToStringConverter::EcmaScriptConverter(); LOG(INFO) << "Hello from GLOG"; fmt::print("Hello, world from FMT!\n"); BOOST_ASSERT(100 == 100); double result; fast_float::from_chars(input.data(), input.data() + input.size(), result); LOG(INFO) << "Answer :" << result; NSArray *frameworks = [NSBundle allFrameworks]; for (NSBundle *framework in frameworks) { NSString *frameworkName = framework.bundleURL.lastPathComponent; if ([frameworkName isEqualToString: @"ReactNativeDependencies.framework"]) { [self loadBundle:framework bundleName:@"ReactNativeDependencies_glog"]; [self loadBundle:framework bundleName:@"ReactNativeDependencies_boost"]; [self loadBundle:framework bundleName:@"ReactNativeDependencies_folly"]; break; } } return YES; } - (void) loadBundle:(NSBundle*)framework bundleName: (NSString*)bundleName { NSBundle *bundle = [NSBundle bundleWithURL:[framework bundleURL]]; NSURL *bundleURL = [bundle URLForResource:bundleName withExtension:@"bundle"]; NSBundle *resourceBundle = [NSBundle bundleWithURL:bundleURL]; NSURL* url = [resourceBundle URLForResource:@"PrivacyInfo" withExtension:@"xcprivacy"]; if (url == nil) { LOG(ERROR) << "Could not find PrivacyInfo.xcprivacy in the " << [bundleName UTF8String] << " bundle"; } else { LOG(INFO) << "Found PrivacyInfo.xcprivacy in " << [bundleName UTF8String] << "."; } } ``` Pull Request resolved: #50050 Reviewed By: javache Differential Revision: D71316215 Pulled By: cipolleschi fbshipit-source-id: 53093f962874101f5618997fdac3dd4550768da5
1 parent fab7fa8 commit 9cf1383

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

scripts/releases/ios-prebuild/compose-framework.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ function copyBundles(
113113
targetArchFolder,
114114
`${scheme}.framework`,
115115
'Resources',
116+
bundleName,
116117
);
117118
if (
118119
!fs.existsSync(path.join(targetArchFolder, `${scheme}.framework`))
@@ -123,7 +124,8 @@ function copyBundles(
123124
console.warn("Source bundle doesn't exist", sourceBundlePath);
124125
}
125126
// A bundle is a directory, so we need to copy the whole directory
126-
execSync(`cp -r ${sourceBundlePath} ${targetBundlePath}`);
127+
execSync(`mkdir -p "${targetBundlePath}"`);
128+
execSync(`cp -r "${sourceBundlePath}/" "${targetBundlePath}"`);
127129
});
128130
} else {
129131
console.warn(`Bundle ${sourceBundlePath} not found`);

scripts/releases/ios-prebuild/configuration.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ const dependencies /*: $ReadOnlyArray<Dependency> */ = [
4848
'src/vlog_is_on.cc',
4949
],
5050
headers: ['src/glog/*.h'],
51-
// resources: ['../third-party-podspecs/glog/PrivacyInfo.xcprivacy'],
51+
resources: ['../third-party-podspecs/glog/PrivacyInfo.xcprivacy'],
5252
headerSkipFolderNames: 'src',
5353
},
5454
settings: {
5555
publicHeaderFiles: './headers',
5656
headerSearchPaths: ['src'],
57-
compilerFlags: ['-Wno-shorten-64-to-32', '-Wno-everything'],
57+
cCompilerFlags: ['-Wno-shorten-64-to-32'],
58+
cxxCompilerFlags: ['-Wno-shorten-64-to-32', `-std=${CPP_STANDARD}`],
5859
defines: [
5960
{name: 'DEFINES_MODULE', value: 'YES'},
6061
{name: 'USE_HEADERMAP', value: 'NO'},
@@ -76,7 +77,6 @@ const dependencies /*: $ReadOnlyArray<Dependency> */ = [
7677
settings: {
7778
publicHeaderFiles: './headers',
7879
headerSearchPaths: ['src'],
79-
compilerFlags: ['-Wno-everything'],
8080
},
8181
},
8282
{
@@ -94,7 +94,7 @@ const dependencies /*: $ReadOnlyArray<Dependency> */ = [
9494
publicHeaderFiles: './include',
9595
headerSearchPaths: ['include'],
9696
linkedLibraries: ['c++'],
97-
compilerFlags: ['-Wno-everything', `-std=${CPP_STANDARD}`],
97+
cxxCompilerFlags: [`-std=${CPP_STANDARD}`],
9898
},
9999
},
100100
{
@@ -107,12 +107,13 @@ const dependencies /*: $ReadOnlyArray<Dependency> */ = [
107107
files: {
108108
sources: ['boost/**/*.hpp', 'dummy.cc'],
109109
headers: ['boost/**/*.hpp'],
110-
// resources: ['../third-party-podspecs/boost/PrivacyInfo.xcprivacy'],
110+
resources: ['../third-party-podspecs/boost/PrivacyInfo.xcprivacy'],
111111
},
112112
settings: {
113113
publicHeaderFiles: './',
114114
headerSearchPaths: ['./'],
115-
compilerFlags: ['-Wno-everything', '-Wno-documentation'],
115+
cCompilerFlags: ['-Wno-documentation'],
116+
cxxCompilerFlags: ['-Wno-documentation', `-std=${CPP_STANDARD}`],
116117
},
117118
},
118119
{
@@ -130,7 +131,7 @@ const dependencies /*: $ReadOnlyArray<Dependency> */ = [
130131
settings: {
131132
publicHeaderFiles: './include',
132133
headerSearchPaths: ['include'],
133-
compilerFlags: ['-Wno-everything', `-std=${CPP_STANDARD}`],
134+
cxxCompilerFlags: [`-std=${CPP_STANDARD}`],
134135
linkedLibraries: ['c++'],
135136
},
136137
},
@@ -158,7 +159,6 @@ const dependencies /*: $ReadOnlyArray<Dependency> */ = [
158159
'SocketRocket/Internal/Security',
159160
'SocketRocket/Internal/Utilities',
160161
],
161-
compilerFlags: ['-Wno-everything'],
162162
},
163163
},
164164
{
@@ -245,8 +245,7 @@ const dependencies /*: $ReadOnlyArray<Dependency> */ = [
245245
'folly/portability/*.h',
246246
'folly/system/*.h',
247247
],
248-
// TODO: When including this we get "failed to scan dependencies" error
249-
// resources: ['../third-party-podspecs/RCT-Folly/PrivacyInfo.xcprivacy'],
248+
resources: ['../third-party-podspecs/RCT-Folly/PrivacyInfo.xcprivacy'],
250249
},
251250
dependencies: [
252251
'glog',
@@ -259,12 +258,12 @@ const dependencies /*: $ReadOnlyArray<Dependency> */ = [
259258
settings: {
260259
publicHeaderFiles: './',
261260
headerSearchPaths: ['./'],
262-
compilerFlags: [
263-
'-Wno-everything',
264-
`-std=${CPP_STANDARD}`,
261+
cCompilerFlags: ['-faligned-new', '-Wno-shorten-64-to-32', '-Wno-comma'],
262+
cxxCompilerFlags: [
265263
'-faligned-new',
266264
'-Wno-shorten-64-to-32',
267265
'-Wno-comma',
266+
`-std=${CPP_STANDARD}`,
268267
],
269268
defines: [
270269
{name: 'USE_HEADERMAP', value: 'NO'},

scripts/releases/ios-prebuild/swift-package.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,15 @@ ${dependencies.map(d => createSwiftTarget(d)).join('')}
6868
*/
6969
function createSwiftTarget(dependency /* :Dependency */) {
7070
// Setup unsafe flags
71-
let unsafeCAndCxxSettings = '';
72-
if (dependency.settings.compilerFlags != null) {
73-
unsafeCAndCxxSettings = `.unsafeFlags([${dependency.settings.compilerFlags.map(flag => `"${flag}"`).join(', ')}]),`;
71+
let unsafeCSettings = '';
72+
if (dependency.settings.cCompilerFlags != null) {
73+
unsafeCSettings = `.unsafeFlags([${dependency.settings.cCompilerFlags.map(flag => `"${flag}"`).join(', ')}]),`;
74+
}
75+
76+
// Add c++ version to c++ settings if provided
77+
let unsafeCxxSettings = '';
78+
if (dependency.settings.cxxCompilerFlags != null) {
79+
unsafeCxxSettings = `.unsafeFlags([${dependency.settings.cxxCompilerFlags.map(flag => `"${flag}"`).join(', ')}]),`;
7480
}
7581

7682
// Setup defines
@@ -120,12 +126,12 @@ function createSwiftTarget(dependency /* :Dependency */) {
120126
publicHeadersPath: "${dependency.settings.publicHeaderFiles}",
121127
cSettings: [
122128
${headerSearchPaths}
123-
${unsafeCAndCxxSettings}
129+
${unsafeCSettings}
124130
${defines}
125131
],
126132
cxxSettings: [
127133
${headerSearchPaths}
128-
${unsafeCAndCxxSettings}
134+
${unsafeCxxSettings}
129135
${defines}
130136
],
131137
linkerSettings: [

scripts/releases/ios-prebuild/types.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export type Define = $ReadOnly<{
3131
export type Settings = $ReadOnly<{
3232
headerSearchPaths?: $ReadOnlyArray<string>,
3333
defines?: $ReadOnlyArray<Define>,
34-
compilerFlags?: $ReadOnlyArray<string>,
34+
cCompilerFlags?: $ReadOnlyArray<string>,
35+
cxxCompilerFlags?: $ReadOnlyArray<string>,
3536
linkedLibraries?: $ReadOnlyArray<string>,
3637
publicHeaderFiles: string,
3738
linkerSettings?: $ReadOnlyArray<string>

0 commit comments

Comments
 (0)