Skip to content

Commit c7c1a89

Browse files
authored
feat: Clangd support (#3069)
## Description This pull request introduces `clangd` support. You can read more about it in [this](software-mansion/react-native-reanimated#6430) awesome PR that bring it to reanimated. For now it supports iOS only as I am not sure if we need it for android here. To make it work, you have build `FabricExample` or `MacOSExample` first. <!-- Description and motivation for this PR. Include 'Fixes #<number>' if this is fixing some issue. --> <!-- Describe how did you test this change here. -->
1 parent 752e469 commit c7c1a89

File tree

11 files changed

+116
-16
lines changed

11 files changed

+116
-16
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ dist/
6565

6666
# generated by bob
6767
/lib/
68+
69+
# clangd
70+
.cache
71+
CompilationDatabase
72+
compile_commands.json

FabricExample/android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ buildscript {
66
targetSdkVersion = 34
77
ndkVersion = "26.1.10909125"
88
kotlinVersion = "1.9.24"
9+
isGHExampleApp = true
910
}
1011
repositories {
1112
google()

FabricExample/ios/FabricExample.xcodeproj/project.pbxproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
5709B34CF0A7D63546082F79 /* Pods-FabricExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FabricExample.release.xcconfig"; path = "Target Support Files/Pods-FabricExample/Pods-FabricExample.release.xcconfig"; sourceTree = "<group>"; };
4444
5B7EB9410499542E8C5724F5 /* Pods-FabricExample-FabricExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FabricExample-FabricExampleTests.debug.xcconfig"; path = "Target Support Files/Pods-FabricExample-FabricExampleTests/Pods-FabricExample-FabricExampleTests.debug.xcconfig"; sourceTree = "<group>"; };
4545
5DCACB8F33CDC322A6C60F78 /* libPods-FabricExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FabricExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
46-
748A2AC40A2F803BAF052F38 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; name = PrivacyInfo.xcprivacy; path = FabricExample/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
46+
748A2AC40A2F803BAF052F38 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = FabricExample/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
4747
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = FabricExample/LaunchScreen.storyboard; sourceTree = "<group>"; };
4848
89C6BE57DB24E9ADA2F236DE /* Pods-FabricExample-FabricExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FabricExample-FabricExampleTests.release.xcconfig"; path = "Target Support Files/Pods-FabricExample-FabricExampleTests/Pods-FabricExample-FabricExampleTests.release.xcconfig"; sourceTree = "<group>"; };
4949
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
@@ -189,6 +189,7 @@
189189
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
190190
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */,
191191
E235C05ADACE081382539298 /* [CP] Copy Pods Resources */,
192+
BDDECB0BB2719FE896F53939 /* [CP-User] Generate metadata for clangd */,
192193
);
193194
buildRules = (
194195
);
@@ -311,6 +312,17 @@
311312
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
312313
showEnvVarsInLog = 0;
313314
};
315+
BDDECB0BB2719FE896F53939 /* [CP-User] Generate metadata for clangd */ = {
316+
isa = PBXShellScriptBuildPhase;
317+
alwaysOutOfDate = 1;
318+
buildActionMask = 2147483647;
319+
files = (
320+
);
321+
name = "[CP-User] Generate metadata for clangd";
322+
runOnlyForDeploymentPostprocessing = 0;
323+
shellPath = /bin/bash;
324+
shellScript = "../../scripts/clangd-generate-xcode-metadata.sh";
325+
};
314326
C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */ = {
315327
isa = PBXShellScriptBuildPhase;
316328
buildActionMask = 2147483647;

FabricExample/ios/Podfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ require Pod::Executable.execute_command('node', ['-p',
55
{paths: [process.argv[1]]},
66
)', __dir__]).strip
77

8+
require_relative '../../scripts/clangd-add-xcode-step.rb'
9+
810
platform :ios, min_ios_version_supported
911
prepare_react_native_project!
1012

@@ -15,6 +17,7 @@ if linkage != nil
1517
end
1618

1719
ENV['RCT_NEW_ARCH_ENABLED'] = '1'
20+
ENV['GH_EXAMPLE_APP_NAME'] = 'FabricExample'
1821

1922
target 'FabricExample' do
2023
config = use_native_modules!
@@ -39,4 +42,6 @@ target 'FabricExample' do
3942
# :ccache_enabled => true
4043
)
4144
end
45+
46+
add_clangd_generation_step()
4247
end

MacOSExample/macos/MacOSExample.xcodeproj/project.pbxproj

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 46;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -151,6 +151,7 @@
151151
381D8A6E24576A4E00465D17 /* Bundle React Native code and images */,
152152
A6395851AE71BEB7A700012B /* [CP] Copy Pods Resources */,
153153
938E3CBCFBD697407DD017DA /* [CP] Embed Pods Frameworks */,
154+
7E6F9CFA6FD8C90D3D4BD9DA /* [CP-User] Generate metadata for clangd */,
154155
);
155156
buildRules = (
156157
);
@@ -291,6 +292,17 @@
291292
shellPath = /bin/sh;
292293
shellScript = "export RCT_METRO_PORT=\"${RCT_METRO_PORT:=8081}\"\necho \"export RCT_METRO_PORT=${RCT_METRO_PORT}\" > \"${SRCROOT}/../node_modules/react-native-macos/scripts/.packager.env\"\nif [ -z \"${RCT_NO_LAUNCH_PACKAGER+xxx}\" ] ; then\n if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then\n if ! curl -s \"http://localhost:${RCT_METRO_PORT}/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly\"\n exit 2\n fi\n else\n open \"$SRCROOT/../node_modules/react-native-macos/scripts/launchPackager.command\" || echo \"Can't start packager automatically\"\n fi\nfi\n";
293294
};
295+
7E6F9CFA6FD8C90D3D4BD9DA /* [CP-User] Generate metadata for clangd */ = {
296+
isa = PBXShellScriptBuildPhase;
297+
alwaysOutOfDate = true;
298+
buildActionMask = 2147483647;
299+
files = (
300+
);
301+
name = "[CP-User] Generate metadata for clangd";
302+
runOnlyForDeploymentPostprocessing = 0;
303+
shellPath = /bin/bash;
304+
shellScript = "../../scripts/clangd-generate-xcode-metadata.sh";
305+
};
294306
938E3CBCFBD697407DD017DA /* [CP] Embed Pods Frameworks */ = {
295307
isa = PBXShellScriptBuildPhase;
296308
buildActionMask = 2147483647;
@@ -389,7 +401,10 @@
389401
CURRENT_PROJECT_VERSION = 1;
390402
ENABLE_BITCODE = NO;
391403
INFOPLIST_FILE = "MacOSExample-iOS/Info.plist";
392-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
404+
LD_RUNPATH_SEARCH_PATHS = (
405+
"$(inherited)",
406+
"@executable_path/Frameworks",
407+
);
393408
OTHER_LDFLAGS = (
394409
"$(inherited)",
395410
"-ObjC",
@@ -410,7 +425,10 @@
410425
CLANG_ENABLE_MODULES = YES;
411426
CURRENT_PROJECT_VERSION = 1;
412427
INFOPLIST_FILE = "MacOSExample-iOS/Info.plist";
413-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
428+
LD_RUNPATH_SEARCH_PATHS = (
429+
"$(inherited)",
430+
"@executable_path/Frameworks",
431+
);
414432
OTHER_LDFLAGS = (
415433
"$(inherited)",
416434
"-ObjC",
@@ -431,7 +449,10 @@
431449
CURRENT_PROJECT_VERSION = 1;
432450
DEAD_CODE_STRIPPING = NO;
433451
INFOPLIST_FILE = "MacOSExample-macos/Info.plist";
434-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
452+
LD_RUNPATH_SEARCH_PATHS = (
453+
"$(inherited)",
454+
"@executable_path/Frameworks",
455+
);
435456
MACOSX_DEPLOYMENT_TARGET = 10.15;
436457
OTHER_LDFLAGS = (
437458
"$(inherited)",
@@ -452,7 +473,10 @@
452473
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
453474
CURRENT_PROJECT_VERSION = 1;
454475
INFOPLIST_FILE = "MacOSExample-macos/Info.plist";
455-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
476+
LD_RUNPATH_SEARCH_PATHS = (
477+
"$(inherited)",
478+
"@executable_path/Frameworks",
479+
);
456480
MACOSX_DEPLOYMENT_TARGET = 10.15;
457481
OTHER_LDFLAGS = (
458482
"$(inherited)",
@@ -520,7 +544,10 @@
520544
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
521545
LD = "";
522546
LDPLUSPLUS = "";
523-
LD_RUNPATH_SEARCH_PATHS = "/usr/lib/swift $(inherited)";
547+
LD_RUNPATH_SEARCH_PATHS = (
548+
/usr/lib/swift,
549+
"$(inherited)",
550+
);
524551
LIBRARY_SEARCH_PATHS = (
525552
"$(SDKROOT)/usr/lib/swift",
526553
"\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
@@ -587,7 +614,10 @@
587614
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
588615
LD = "";
589616
LDPLUSPLUS = "";
590-
LD_RUNPATH_SEARCH_PATHS = "/usr/lib/swift $(inherited)";
617+
LD_RUNPATH_SEARCH_PATHS = (
618+
/usr/lib/swift,
619+
"$(inherited)",
620+
);
591621
LIBRARY_SEARCH_PATHS = (
592622
"$(SDKROOT)/usr/lib/swift",
593623
"\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",

MacOSExample/macos/Podfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
require_relative '../node_modules/react-native-macos/scripts/react_native_pods'
22
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
3+
require_relative '../../scripts/clangd-add-xcode-step.rb'
34

45
prepare_react_native_project!
56

7+
ENV['GH_EXAMPLE_APP_NAME'] = 'MacOSExample'
8+
69
target 'MacOSExample-macOS' do
710
platform :macos, '10.15'
811

@@ -34,4 +37,6 @@ target 'MacOSExample-macOS' do
3437
end
3538
end
3639
end
40+
41+
add_clangd_generation_step()
3742
end

MacOSExample/macos/Podfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ PODS:
44
- FBLazyVector (0.74.6)
55
- fmt (9.1.0)
66
- glog (0.3.5)
7-
- hermes-engine (0.74.5):
8-
- hermes-engine/Pre-built (= 0.74.5)
9-
- hermes-engine/Pre-built (0.74.5)
7+
- hermes-engine (0.74.6):
8+
- hermes-engine/Pre-built (= 0.74.6)
9+
- hermes-engine/Pre-built (0.74.6)
1010
- RCT-Folly (2024.01.01.00):
1111
- boost
1212
- DoubleConversion
@@ -1443,11 +1443,11 @@ EXTERNAL SOURCES:
14431443

14441444
SPEC CHECKSUMS:
14451445
boost: 0686b6af8cbd638c784fea5afb789be66699823c
1446-
DoubleConversion: 5b92c4507c560bb62e7aa1acdf2785ea3ff08b3b
1446+
DoubleConversion: acaf5db79676d2e9119015819153f0f99191de12
14471447
FBLazyVector: 8f41053475f558b29633b434bd62929813a38560
14481448
fmt: 03574da4b7ba40de39da59677ca66610ce8c4a02
1449-
glog: ba31c1afa7dcf1915a109861bccdb4421be6175b
1450-
hermes-engine: 8c1577f3fdb849cbe7729c2e7b5abc4b845e88f8
1449+
glog: 6df0a3d6e2750a50609471fd1a01fd2948d405b5
1450+
hermes-engine: 2102c92e54a031a270fd1fe84169ec8a0901b7bd
14511451
RCT-Folly: 2edbb9597acadc2312235c7ad6243d49852047a3
14521452
RCTDeprecation: 5f1d7e1f8ef6c53f0207e3ac0d0ca23575e8a6ab
14531453
RCTRequired: 200cf97fbe1ff2c9573d9f7b2243b6bd9330b6b8
@@ -1496,12 +1496,12 @@ SPEC CHECKSUMS:
14961496
React-utils: d1f30e28b14bea6aa6b009be03ab502bbf2cf5c6
14971497
ReactCommon: 68cae4af53cf2d34e6a26c0099f434f170495dd1
14981498
RNCAsyncStorage: ec53e44dc3e75b44aa2a9f37618a49c3bc080a7a
1499-
RNGestureHandler: 28078232f2868d3dcb4d4b6c8ab8691700187664
1499+
RNGestureHandler: 742f027eb4bca8033a2d43582358645c71d5f5eb
15001500
RNReanimated: 45553a3ae29a75a76269595f8554d07d4090e392
15011501
RNSVG: 4590aa95758149fa27c5c83e54a6a466349a1688
15021502
SocketRocket: f6c6249082c011e6de2de60ed641ef8bbe0cfac9
15031503
Yoga: 2b5a8ace4c52fd28c52de828b9a66aede21c3a9c
15041504

1505-
PODFILE CHECKSUM: a03a1b37f876fddd02813d86862de4a117e90221
1505+
PODFILE CHECKSUM: 3d6bcfcb4beca113bbf03f2652ec9272037c8111
15061506

15071507
COCOAPODS: 1.15.2

RNGestureHandler.podspec

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
require "json"
22

3+
4+
is_gh_example_app = ENV["GH_EXAMPLE_APP_NAME"] != nil
5+
6+
compilation_metadata_dir = "CompilationDatabase"
7+
compilation_metadata_generation_flag = is_gh_example_app ? '-gen-cdb-fragment-path ' + compilation_metadata_dir : ''
8+
39
Pod::Spec.new do |s|
410
# NPM package specification
511
package = JSON.parse(File.read(File.join(File.dirname(__FILE__), "package.json")))
@@ -14,6 +20,9 @@ Pod::Spec.new do |s|
1420
s.source_files = "apple/**/*.{h,m,mm}"
1521
s.requires_arc = true
1622
s.platforms = { ios: '11.0', tvos: '11.0', osx: '10.15', visionos: '1.0' }
23+
s.xcconfig = {
24+
"OTHER_CFLAGS" => "$(inherited) " + compilation_metadata_generation_flag
25+
}
1726

1827
if defined?(install_modules_dependencies()) != nil
1928
install_modules_dependencies(s);

android/build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import groovy.json.JsonSlurper
2+
import com.android.build.gradle.tasks.ExternalNativeBuildJsonTask
23

34
buildscript {
45
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['RNGH_kotlinVersion']
@@ -27,6 +28,10 @@ def safeExtGet(prop, fallback) {
2728
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
2829
}
2930

31+
def isGHExampleApp() {
32+
return safeExtGet("isGHExampleApp", false)
33+
}
34+
3035
def resolveReactNativeDirectory() {
3136
def reactNativeLocation = safeExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
3237
if (reactNativeLocation != null) {
@@ -170,6 +175,20 @@ android {
170175
}
171176
}
172177
}
178+
179+
if (isGHExampleApp()) {
180+
tasks.withType(ExternalNativeBuildJsonTask) {
181+
compileTask ->
182+
compileTask.doLast {
183+
def rootDir = new File("${project.projectDir}/..")
184+
def generated = new File("${compileTask.abi.getCxxBuildFolder()}/compile_commands.json")
185+
def output = new File("${rootDir}/compile_commands.json")
186+
output.text = generated.text
187+
188+
println("Generated clangd metadata.")
189+
}
190+
}
191+
}
173192
}
174193

175194
def kotlin_version = safeExtGet('kotlinVersion', project.properties['RNGH_kotlinVersion'])

scripts/clangd-add-xcode-step.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def add_clangd_generation_step()
2+
generator_script_path = '../../scripts/clangd-generate-xcode-metadata.sh'
3+
4+
script_phase :name => 'Generate metadata for clangd', :script => generator_script_path, :shell_path => '/bin/bash', :always_out_of_date => 'true', :execution_position => :after_compile
5+
end

0 commit comments

Comments
 (0)