Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@
"scripts/setup-apple-spm.js",
"scripts/spm",
"scripts/xcode/asset-catalog.sh",
"scripts/xcode/ccache-clang.sh",
"scripts/xcode/ccache-clang++.sh",
"scripts/xcode/ccache.conf",
"scripts/xcode/with-environment.sh",
"sdks/.hermesv1version",
Expand Down
30 changes: 30 additions & 0 deletions packages/react-native/scripts/cocoapods/__tests__/utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,36 @@ def test_add_ndebug_flag_to_pods_in_release
assert_equal("$(inherited) -DNDEBUG", custom_release_config2.build_settings["OTHER_CPLUSPLUSFLAGS"])
assert_equal("$(inherited) -DNDEBUG", custom_release_config3.build_settings["OTHER_CPLUSPLUSFLAGS"])
end

# ================================ #
# Test - ccache launcher script #
# ================================ #

def test_ccacheLauncherScript_embedsResolvedCcachePath
# Act
script = ReactNativePodsUtils.ccache_launcher_script("clang", "/opt/homebrew/bin/ccache", "/app/rn/scripts/xcode/ccache.conf")

# Assert
assert_equal('exec "/opt/homebrew/bin/ccache" clang "$@"', script.lines.last.chomp)
end

def test_ccacheLauncherScript_embedsResolvedConfigPath
# Act
script = ReactNativePodsUtils.ccache_launcher_script("clang", "/opt/homebrew/bin/ccache", "/app/rn/scripts/xcode/ccache.conf")

# Assert
assert(script.include?("REACT_NATIVE_CCACHE_CONFIGPATH=/app/rn/scripts/xcode/ccache.conf"))
assert(script.include?('${CCACHE_CONFIGPATH:-$REACT_NATIVE_CCACHE_CONFIGPATH}'))
end

def test_ccacheLauncherScript_forCpp_execsClangpp
# Act
script = ReactNativePodsUtils.ccache_launcher_script("clang++", "/usr/local/bin/ccache", "/tmp/ccache.conf")

# Assert
assert_equal('exec "/usr/local/bin/ccache" clang++ "$@"', script.lines.last.chomp)
end

end

# ===== #
Expand Down
40 changes: 37 additions & 3 deletions packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,39 @@ def self.set_build_setting(installer, build_setting:, value:, config_name: nil)
end
end

# Generated rather than shipped: a compiler launcher gets none of Xcode's
# environment, so both paths have to be baked in at install time.
def self.ccache_launcher_script(compiler, ccache_path, config_path)
<<~SH
#!/bin/sh
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

# Generated by pod install. Edit react_native_pods.rb, not this file.

REACT_NATIVE_CCACHE_CONFIGPATH=#{config_path}
# Provide our config file if none is already provided
export CCACHE_CONFIGPATH="${CCACHE_CONFIGPATH:-$REACT_NATIVE_CCACHE_CONFIGPATH}"

exec "#{ccache_path}" #{compiler} "$@"
SH
end

def self.generate_ccache_launchers(installer, react_native_path, ccache_path)
pods_root = installer.sandbox.root.to_s
config_path = File.expand_path(
File.join(react_native_path, 'scripts', 'xcode', 'ccache.conf'),
Pod::Config.instance.installation_root.to_s
)
{ 'ccache-clang.sh' => 'clang', 'ccache-clang++.sh' => 'clang++' }.each do |name, compiler|
path = File.join(pods_root, name)
File.write(path, self.ccache_launcher_script(compiler, ccache_path, config_path))
File.chmod(0755, path)
end
end

def self.set_ccache_compiler_and_linker_build_settings(installer, react_native_path, ccache_enabled)
projects = self.extract_projects(installer)

Expand All @@ -169,8 +202,8 @@ def self.set_ccache_compiler_and_linker_build_settings(installer, react_native_p
end

# Using scripts wrapping the ccache executable, to allow injection of configurations
ccache_clang_sh = File.join("$(REACT_NATIVE_PATH)", 'scripts', 'xcode', 'ccache-clang.sh')
ccache_clangpp_sh = File.join("$(REACT_NATIVE_PATH)", 'scripts', 'xcode', 'ccache-clang++.sh')
ccache_clang_sh = File.join("$(PODS_ROOT)", 'ccache-clang.sh')
ccache_clangpp_sh = File.join("$(PODS_ROOT)", 'ccache-clang++.sh')

if ccache_available and ccache_enabled
Pod::UI.puts("#{message_prefix}: Setting CC, LD, CXX & LDPLUSPLUS build settings")
Expand All @@ -182,11 +215,12 @@ def self.set_ccache_compiler_and_linker_build_settings(installer, react_native_p
config.build_settings["LD"] = ccache_clang_sh
config.build_settings["CXX"] = ccache_clangpp_sh
config.build_settings["LDPLUSPLUS"] = ccache_clangpp_sh
config.build_settings["CCACHE_BINARY"] = ccache_path
end

project.save()
end

self.generate_ccache_launchers(installer, react_native_path, ccache_path)
elsif ccache_available and !ccache_enabled
Pod::UI.puts("#{message_prefix}: Pass ':ccache_enabled => true' to 'react_native_post_install' in your Podfile or set environment variable 'USE_CCACHE=1' to increase the speed of subsequent builds")
elsif !ccache_available and ccache_enabled
Expand Down
14 changes: 0 additions & 14 deletions packages/react-native/scripts/xcode/ccache-clang++.sh

This file was deleted.

14 changes: 0 additions & 14 deletions packages/react-native/scripts/xcode/ccache-clang.sh

This file was deleted.

Loading