diff --git a/apple/internal/resource_actions/png.bzl b/apple/internal/resource_actions/png.bzl index fddb9af401..2357f32ecc 100644 --- a/apple/internal/resource_actions/png.bzl +++ b/apple/internal/resource_actions/png.bzl @@ -29,29 +29,41 @@ def copy_png(*, actions, input_file, output_file, platform_prerequisites): platform_prerequisites: Struct containing information on the platform being targeted. """ - # Xcode uses `xcrun copypng -strip-PNG-text -compress IN OUT`. But pngcrush - # is a perl script that doesn't properly handle when the process dies via a - # signal, so instead just expand out the comment to skip the script and - # directly run Xcode's copy of pngcrush with the same args. - apple_support.run( - actions = actions, - apple_fragment = platform_prerequisites.apple_fragment, - arguments = [ - "pngcrush", - # -compress expands to: - "-q", - "-iphone", - "-f", - "0", - # "-strip-PNG-text", - "-rem", - "text", - input_file.path, - output_file.path, - ], - executable = "/usr/bin/xcrun", - inputs = [input_file], - mnemonic = "CopyPng", - outputs = [output_file], - xcode_config = platform_prerequisites.xcode_version_config, + # Xcode does not use `pngcrush` on macOS, but allow override using a feature. + should_compress_png = ( + platform_prerequisites.platform_type != apple_common.platform_type.macos or + "apple.macos_compress_png_files" in platform_prerequisites.features ) + + if should_compress_png: + # Xcode uses `xcrun copypng -strip-PNG-text -compress IN OUT`. But pngcrush + # is a perl script that doesn't properly handle when the process dies via a + # signal, so instead just expand out the comment to skip the script and + # directly run Xcode's copy of pngcrush with the same args. + apple_support.run( + actions = actions, + apple_fragment = platform_prerequisites.apple_fragment, + arguments = [ + "pngcrush", + # -compress expands to: + "-q", + "-iphone", + "-f", + "0", + # "-strip-PNG-text", + "-rem", + "text", + input_file.path, + output_file.path, + ], + executable = "/usr/bin/xcrun", + inputs = [input_file], + mnemonic = "CopyPng", + outputs = [output_file], + xcode_config = platform_prerequisites.xcode_version_config, + ) + else: + actions.symlink( + target_file = input_file, + output = output_file, + ) diff --git a/doc/resources.md b/doc/resources.md index ea1e08574a..578c3225c6 100644 --- a/doc/resources.md +++ b/doc/resources.md @@ -423,8 +423,9 @@ on your use case for the resources. * `.strings` and `.plist` files. string and generic plist (i.e. non Info.plist files) files are processed using plutil to convert them into binary format, to reduce their size. -* `.png` files: PNG files are processed using copypng to optimize them for iOS - devices. +* `.png` files: PNG files are processed using `copypng` to optimize them for + iOS devices. This is disabled by default on macOS, but can be enabled with + the `apple.macos_compress_png_files` feature. * `.xib` files: XIB files are processed using `ibtoold`. * `.xcdatamodel` and `.xcmappingmodel` files: These files are processed with `momc` and `mapc` respectively.