创建具有目标 Sharpie 的绑定Creating Bindings with Objective Sharpie

本部分介绍了客观 Sharpie,Xamarin 的命令行工具,该工具用于自动执行创建到目标 C 库的绑定过程This section provides an introduction to Objective Sharpie, Xamarin's command line tool used to automate the process of creating a binding to an Objective-C Library

概述Overview

客观 Sharpie 是一个命令行工具,可帮助启动绑定的第一步。Objective Sharpie is a command line tool to help bootstrap the first pass of a binding. 它的工作原理是分析本机库的标头文件,将公共 API 映射到绑定定义(以前手动完成的进程)。It works by parsing the header files of a native library to map the public API into the binding definition (a process that previously was manually done).

客观 Sharpie 使用 Clang 分析标头文件,因此绑定的完全一致。Objective Sharpie uses Clang parse header files, so the binding is as exact and thorough as possible. 这可以极大地减少生成质量绑定所要花费的时间和精力。This can greatly reduce the time and effort it takes to produce a quality binding.

重要

客观 Sharpie 是一款面向经验丰富的 Xamarin 开发人员的工具,具有客观-C (和 extension,C)的高级知识。Objective Sharpie is a tool for experienced Xamarin developers with advanced knowledge of Objective-C (and by extension, C). 在尝试绑定目标 C 库之前,您应该大致了解如何在命令行上生成本机库(并且充分了解本机库的工作方式)。Before attempting to bind an Objective-C library you should have solid knowledge of how to build the native library on the command line (and a good understanding of how the native library works).

历史记录History

过去三年,我们一直在 Xamarin 上不断发展并使用目标 Sharpie。We have been evolving and using the Objective Sharpie internally at Xamarin for the last three years. 作为证明目标 Sharpie 的强大功能,从 iOS 8、Mac OS X 10.10 和 watchOS 2.0 开始,因为 iOS 8、和在中引入的 Api 与目标 Sharpie 完全相同。As a testament to the power of Objective Sharpie, APIs introduced in Xamarin.iOS and Xamarin.Mac since iOS 8, Mac OS X 10.10, and watchOS 2.0 were bootstrapped entirely with Objective Sharpie. Xamarin 很大程度上依赖于客观 Sharpie 来构建自己的产品。Xamarin relies heavily on Objective Sharpie internally for building its own products.

但是,客观 Sharpie 是一个非常高级的工具,它需要对目标-C 和 C 的高级了解、如何在命令行中使用 clang 编译器,以及如何将本机库组合在一起。However, Objective Sharpie is a very advanced tool that requires advanced knowledge of Objective-C and C, how to use the clang compiler on the command line, and generally how native libraries are put together. 由于这是一个较高的条形,因此,我们认为具有 GUI 向导会设置错误的预期,因此,目标 Sharpie 当前仅可用作命令行工具。Because of this high bar, we felt that having a GUI wizard sets the wrong expectations, and as such, Objective Sharpie is currently only available as a command line tool.