[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/pythonthings/cefpython/cefpython55/tools/build_module.py [Back]  [Original]

# Copyright (c) 2017 The CEF Python authors. All rights reserved.
# Licensed under the BSD 3-clause license.

"""
build_module.py is for internal use only - called by build.py.
This is Cython's setup for building the cefpython module
"""

# Use setuptools so that "Visual C++ compiler for Python 2.7" tools
# can be used. Otherwise "Unable to find vcvarsall.bat" error occurs.
try:
    from setuptools import setup
    from setuptools import Extension
except ImportError:
    from distutils.core import setup
    from distutils.extension import Extension

# Use "Extension" from Cython.Distutils so that "cython_directives" works
from Cython.Distutils import build_ext, Extension
from Cython.Compiler import Options
# noinspection PyUnresolvedReferences
from Cython.Compiler.ModuleNode import ModuleNode
from common import *
import sys
import platform
import Cython
import os

# Must monkey patch Cython's ModuleNode to inject custom C++ code
# in the generated cefpython.cpp. This is a fix for an error on Mac:
# > ImportError: dynamic module does not define init function
# To get rid of CEF's undefined symbol error when importing module
# it was required to pass "-fvisibility=hidden" and "-Wl,-dead_strip"
# flags. However these flags cause the "initcefpython_py27" Python
# Module Initialization function to be hidden as well. To workaround
# this it is required to add default visibility attribute to the
# signature of that init function.
#
# Original definition in Python 2.7:
# | https://github.com/python/cpython/blob/2.7/Include/pyport.h
# > define PyMODINIT_FUNC extern "C" __declspec(dllexport) void
#
# Original definition in Python 3.4 / 3.5 / 3.6:
# > define PyMODINIT_FUNC extern "C" __declspec(dllexport) PyObject*

if MAC:
    g_generate_extern_c_macro_definition_old = (
            ModuleNode.generate_extern_c_macro_definition)

    def generate_extern_c_macro_definition(self, code):
        # This code is written to both cefpython.h and cefpython.cpp
        g_generate_extern_c_macro_definition_old(self, code)
        code.putln("// Added by: cefpython/tools/build_module.py")
        code.putln("#undef PyMODINIT_FUNC")
        if sys.version_info[:2] == (2, 7):
            code.putln("#define PyMODINIT_FUNC extern \"C\""
                       " __attribute__((visibility(\"default\"))) void")
        else:
            code.putln("#define PyMODINIT_FUNC extern \"C\""
                       " __attribute__((visibility(\"default\"))) PyObject*")
    # Overwrite Cython function
    ModuleNode.generate_extern_c_macro_definition = (
            generate_extern_c_macro_definition)


# Constants
FAST_FLAG = False

# Cython options. Stop on first error, otherwise hundreds
# of errors appear in the console.
Options.fast_fail = True


def main():
    global FAST_FLAG
    if len(sys.argv) > 1 and "--fast" in sys.argv:
        # Fast mode disables optimization flags
        print("[build_module.py] FAST mode On")
        FAST_FLAG = True
        sys.argv.remove("--fast")

    if len(sys.argv) 

Web Proxy Viewer  |  New URL  |  Original Page