Skip to content

Commit 743f181

Browse files
authored
Merge pull request opencv#19088 from Rightpoint:task/colejd/make-xcframework-output-path-explicit
Make xcframework output path argument explicit and required * Make output path argument explicit and required * Improve xcframework documentation * Add TODOs for future breaking changes on build_framework.py scripts
1 parent dd1494e commit 743f181

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

platforms/apple/build_xcframework.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
Any arguments that are not recognized by this script are passed through to the ios/osx build_framework.py scripts.
2828
"""
2929
parser = argparse.ArgumentParser(description=description, epilog=epilog)
30-
parser.add_argument('out', metavar='OUTDIR', help='The directory where the xcframework will be created')
30+
parser.add_argument('-o', '--out', metavar='OUTDIR', help='<Required> The directory where the xcframework will be created', required=True)
3131
parser.add_argument('--framework_name', default='opencv2', help='Name of OpenCV xcframework (default: opencv2, will change to OpenCV in future version)')
3232
parser.add_argument('--iphoneos_archs', default=None, help='select iPhoneOS target ARCHS. Default is "armv7,arm64"')
3333
parser.add_argument('--iphonesimulator_archs', default=None, help='select iPhoneSimulator target ARCHS. Default is "x86_64,arm64"')
@@ -81,26 +81,26 @@ def get_or_create_build_folder(base_dir, platform):
8181
if iphoneos_archs:
8282
build_folder = get_or_create_build_folder(args.out, "iphoneos")
8383
build_folders.append(build_folder)
84-
command = ["python3", ios_script_path, "--iphoneos_archs", iphoneos_archs, "--framework_name", args.framework_name, "--build_only_specified_archs", build_folder] + unknown_args
84+
command = ["python3", ios_script_path, build_folder, "--iphoneos_archs", iphoneos_archs, "--framework_name", args.framework_name, "--build_only_specified_archs"] + unknown_args
8585
print_header("Building iPhoneOS frameworks")
8686
print(command)
8787
execute(command, cwd=os.getcwd())
8888
if iphonesimulator_archs:
8989
build_folder = get_or_create_build_folder(args.out, "iphonesimulator")
9090
build_folders.append(build_folder)
91-
command = ["python3", ios_script_path, "--iphonesimulator_archs", iphonesimulator_archs, "--framework_name", args.framework_name, "--build_only_specified_archs", build_folder] + unknown_args
91+
command = ["python3", ios_script_path, build_folder, "--iphonesimulator_archs", iphonesimulator_archs, "--framework_name", args.framework_name, "--build_only_specified_archs"] + unknown_args
9292
print_header("Building iPhoneSimulator frameworks")
9393
execute(command, cwd=os.getcwd())
9494
if macos_archs:
9595
build_folder = get_or_create_build_folder(args.out, "macos")
9696
build_folders.append(build_folder)
97-
command = ["python3", osx_script_path, "--macos_archs", macos_archs, "--framework_name", args.framework_name, "--build_only_specified_archs", build_folder] + unknown_args
97+
command = ["python3", osx_script_path, build_folder, "--macos_archs", macos_archs, "--framework_name", args.framework_name, "--build_only_specified_archs"] + unknown_args
9898
print_header("Building MacOS frameworks")
9999
execute(command, cwd=os.getcwd())
100100
if catalyst_archs:
101101
build_folder = get_or_create_build_folder(args.out, "catalyst")
102102
build_folders.append(build_folder)
103-
command = ["python3", osx_script_path, "--catalyst_archs", catalyst_archs, "--framework_name", args.framework_name, "--build_only_specified_archs", build_folder] + unknown_args
103+
command = ["python3", osx_script_path, build_folder, "--catalyst_archs", catalyst_archs, "--framework_name", args.framework_name, "--build_only_specified_archs"] + unknown_args
104104
print_header("Building Catalyst frameworks")
105105
execute(command, cwd=os.getcwd())
106106

platforms/apple/readme.md

+19-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ You'll need the following to run these steps:
1111
You can then run build_xcframework.py, as below:
1212
```
1313
cd ~/<my_working_directory>
14-
python opencv/platforms/apple/build_xcframework.py ./build_xcframework
14+
python opencv/platforms/apple/build_xcframework.py --out ./build_xcframework
1515
```
1616

1717
Grab a coffee, because you'll be here for a while. By default this builds OpenCV for 8 architectures across 4 platforms:
@@ -25,16 +25,32 @@ If everything's fine, you will eventually get `opencv2.xcframework` in the outpu
2525

2626
The script has some configuration options to exclude platforms and architectures you don't want to build for. Use the `--help` flag for more information.
2727

28+
## How it Works
29+
30+
This script generates a fat `.framework` for each platform you specify, and stitches them together into a `.xcframework`. This file can be used to support the same architecture on different platforms, which fat `.framework`s don't allow. To build the intermediate `.framework`s, `build_xcframework.py` leverages the `build_framework.py` scripts in the ios and osx platform folders.
31+
32+
### Passthrough Arguments
33+
34+
Any arguments that aren't recognized by `build_xcframework.py` will be passed to the platform-specific `build_framework.py` scripts. The `--without` flag mentioned in the examples is an example of this in action. For more info, see the `--help` info for those scripts.
35+
2836
## Examples
2937

3038
You may override the defaults by specifying a value for any of the `*_archs` flags. For example, if you want to build for arm64 on every platform, you can do this:
3139

3240
```
33-
python build_xcframework.py somedir --iphoneos_archs arm64 --iphonesimulator_archs arm64 --macos_archs arm64 --catalyst_archs arm64
41+
python build_xcframework.py --out somedir --iphoneos_archs arm64 --iphonesimulator_archs arm64 --macos_archs arm64 --catalyst_archs arm64
3442
```
3543

44+
3645
If you want to build only for certain platforms, you can supply the `--build_only_specified_archs` flag, which makes the script build only the archs you directly ask for. For example, to build only for Catalyst, you can do this:
3746

3847
```
39-
python build_xcframework.py somedir --catalyst_archs x86_64,arm64 --build_only_specified_archs
48+
python build_xcframework.py --out somedir --catalyst_archs x86_64,arm64 --build_only_specified_archs
49+
```
50+
51+
You can also build without OpenCV functionality you don't need. You can do this by using the `--without` flag, which you use once per item you want to go without. For example, if you wanted to compile without `video` or `objc`, you'd can do this:
52+
53+
```
54+
python build_xcframework.py --out somedir --without video --without objc
4055
```
56+
(if you have issues with this, try using `=`, e.g. `--without=video --without=objc`, and file an issue on GitHub.)

platforms/ios/build_framework.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,12 @@ def copy_samples(self, outdir):
490490
if __name__ == "__main__":
491491
folder = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "../.."))
492492
parser = argparse.ArgumentParser(description='The script builds OpenCV.framework for iOS.')
493+
# TODO: When we can make breaking changes, we should make the out argument explicit and required like in build_xcframework.py.
493494
parser.add_argument('out', metavar='OUTDIR', help='folder to put built framework')
494495
parser.add_argument('--opencv', metavar='DIR', default=folder, help='folder with opencv repository (default is "../.." relative to script location)')
495496
parser.add_argument('--contrib', metavar='DIR', default=None, help='folder with opencv_contrib repository (default is "None" - build only main framework)')
496-
parser.add_argument('--without', metavar='MODULE', default=[], action='append', help='OpenCV modules to exclude from the framework')
497-
parser.add_argument('--disable', metavar='FEATURE', default=[], action='append', help='OpenCV features to disable (add WITH_*=OFF)')
497+
parser.add_argument('--without', metavar='MODULE', default=[], action='append', help='OpenCV modules to exclude from the framework. To exclude multiple, specify this flag again, e.g. "--without video --without objc"')
498+
parser.add_argument('--disable', metavar='FEATURE', default=[], action='append', help='OpenCV features to disable (add WITH_*=OFF). To disable multiple, specify this flag again, e.g. "--disable tbb --disable openmp"')
498499
parser.add_argument('--dynamic', default=False, action='store_true', help='build dynamic framework (default is "False" - builds static framework)')
499500
parser.add_argument('--disable-bitcode', default=False, dest='bitcodedisabled', action='store_true', help='disable bitcode (enabled by default)')
500501
parser.add_argument('--iphoneos_deployment_target', default=os.environ.get('IPHONEOS_DEPLOYMENT_TARGET', IPHONEOS_DEPLOYMENT_TARGET), help='specify IPHONEOS_DEPLOYMENT_TARGET')

platforms/osx/build_framework.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ def getInfoPlist(self, builddirs):
5858
if __name__ == "__main__":
5959
folder = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "../.."))
6060
parser = argparse.ArgumentParser(description='The script builds OpenCV.framework for OSX.')
61+
# TODO: When we can make breaking changes, we should make the out argument explicit and required like in build_xcframework.py.
6162
parser.add_argument('out', metavar='OUTDIR', help='folder to put built framework')
6263
parser.add_argument('--opencv', metavar='DIR', default=folder, help='folder with opencv repository (default is "../.." relative to script location)')
6364
parser.add_argument('--contrib', metavar='DIR', default=None, help='folder with opencv_contrib repository (default is "None" - build only main framework)')
64-
parser.add_argument('--without', metavar='MODULE', default=[], action='append', help='OpenCV modules to exclude from the framework')
65-
parser.add_argument('--disable', metavar='FEATURE', default=[], action='append', help='OpenCV features to disable (add WITH_*=OFF)')
65+
parser.add_argument('--without', metavar='MODULE', default=[], action='append', help='OpenCV modules to exclude from the framework. To exclude multiple, specify this flag again, e.g. "--without video --without objc"')
66+
parser.add_argument('--disable', metavar='FEATURE', default=[], action='append', help='OpenCV features to disable (add WITH_*=OFF). To disable multiple, specify this flag again, e.g. "--disable tbb --disable openmp"')
6667
parser.add_argument('--dynamic', default=False, action='store_true', help='build dynamic framework (default is "False" - builds static framework)')
6768
parser.add_argument('--enable_nonfree', default=False, dest='enablenonfree', action='store_true', help='enable non-free modules (disabled by default)')
6869
parser.add_argument('--macosx_deployment_target', default=os.environ.get('MACOSX_DEPLOYMENT_TARGET', MACOSX_DEPLOYMENT_TARGET), help='specify MACOSX_DEPLOYMENT_TARGET')

0 commit comments

Comments
 (0)