Skip to content

Building Swift bindings with Xcode

To generate a modulemap defining CppBind generated bindings as a submodule of the Xcode framework, the user adds another configuration file containing the following configuration:

rules:
  swift.code_snippets:
    !include swift/modulemap_snippets.yaml

var_def:
  !include modulemap_variable_definitions.yaml

Here we added the required snippets and variables for modulemap generation. There are two variables defined in modulemap_variable_definitions.yaml:

# Copyright (c) 2022 PicsArt, Inc.
# All rights reserved. Use of this source code is governed by a
# MIT-style license that can be found in the LICENSE file.

modulemap_file_fullname:
  inheritable: true
  default: "{{cxx_out_dir + pat_sep}}CppBind.modulemap"
  allowed_on: [ root ]

modulemap_export:
  inheritable: true
  default: |
    export *
    module * { export * }
  allowed_on: [ root ]

The first is the full path of the modulemap file, and the second is the export declaration to define imported modules that will be exported.

Additionally c_wrapper_lib_name and cxx_helpers_out_rel_path should be properly defined.

cxx_helpers_out_rel_path: ''
c_wrapper_lib_name: <FrameworkName>.<CBindingsSubmoduleName>

Here cxx_helpers_out_rel_path is set to an empty string in order to not generate relative includes for CppBind C helpers.

For the complete example, follow the link: Modulemap Example.


Last update: December 1, 2022