GithubHelp home page GithubHelp logo

lzhangjianjunl / clang-as-ios-dylib Goto Github PK

View Code? Open in Web Editor NEW

This project forked from facebookarchive/clang-as-ios-dylib

0.0 2.0 0.0 193 KB

A workaround to build iOS dynamic libraries from Xcode.

License: Other

Python 100.00%

clang-as-ios-dylib's Introduction

Archived Repo

This is an archived project and is no longer supported or updated by Facebook. Please do not file issues or pull-requests against this repo. If you wish to continue to develop this code yourself, we recommend you fork it.

This hack was useful for convincing Xcode to make iOS dynamic libraries in the days of Xcode 5. With Xcode 6, Apple introduced Frameworks on iOS which are pretty much equivalent to dylibs but with a different packaging structure. Frameworks should satisfy all use cases for clang-as-ios-dylib.

clang-as-ios-dylib

clang-as-ios-dylib is a workaround for building iOS dynamic libraries from Xcode. Most importantly, it lets Xcode build iOS dylibs without requiring any modifications to the Xcode installation.

It works by tricking Xcode into building an OS X dynamic library as if it were an iOS dynamic library. By overriding CC and LD, we make Xcode call a wrapper script instead of directly calling clang, and our wrapper swaps the OS X compile flags for iOS flags.

Only iphonesimulator dylibs are supported now, but it would be possible to add device support if needed.

Usage

  1. Copy the clang-as-ios-dylib code into your repo:
cd Vendor
mkdir clang-as-ios-dylib
cd clang-as-ios-dylib
curl -L https://github.com/facebook/clang-as-ios-dylib/archive/master.tar.gz | tar zxvf - --strip-components=1
  1. In Xcode, create a new OS X Cocoa Library target.

  2. In the project, create a new Configuration Settings File (.xcconfig) file with the following contents:

// The following can be one of 'latest', 'earliest', or a specific
// SDK version like '7.0', or '6.1'.
CAID_BASE_SDK_VERSION = latest
CAID_IPHONEOS_DEPLOYMENT_TARGET = latest

CAID_LINKS_PATH = $(PROJECT_DIR)/../Vendor/clang-as-ios-dylib/links

LD = $(CAID_LINKS_PATH)/ld-iphonesimulator-$(CAID_BASE_SDK_VERSION)-targeting-$(CAID_IPHONEOS_DEPLOYMENT_TARGET)
CC = $(CAID_LINKS_PATH)/cc-iphonesimulator-$(CAID_BASE_SDK_VERSION)-targeting-$(CAID_IPHONEOS_DEPLOYMENT_TARGET)
  1. In your project’s Info settings panel, for each build configuration, select the xcconfig file created in #2 for your target.

  2. Change references to Cocoa.framework to Foundation.framework:

  • In your .pch file, change #import <Cocoa/Cocoa.h> to #import <Foundation/Foundation.h>.
  • In your target's Build Phases panel, under Link Binary With Libraries, remove Cocoa.framework and add Foundation.framework.

Alternatives

The other possibility is modifying some of Xcode’s internal configuration files so that Xcode understands iOS dylibs again. Internally, Xcode already knows how to build iOS dylibs - it’s just that Apple strips some configuration items to prevent it.

See: http://sumgroup.wikispaces.com/iPhone_Dynamic_Library

The downside to this approach is that everyone on your team must also modify their Xcode installation.

License

BSD License

clang-as-ios-dylib
Copyright (c) 2013, Facebook, Inc.  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

clang-as-ios-dylib's People

Contributors

fpotter avatar extrememan avatar ryanrhee avatar

Watchers

James Cloos avatar JingCheng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.