Skip to content

Instantly share code, notes, and snippets.

@thlorenz
Last active August 26, 2018 15:05
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save thlorenz/b92c6d98df17be082271 to your computer and use it in GitHub Desktop.
Save thlorenz/b92c6d98df17be082271 to your computer and use it in GitHub Desktop.
Generating Xcode projects from Node.js binding repos via gyp

This is specifically tailored to Node.js binding projects in which case the C++ layer is always a library.

Clone gyp:

git clone --depth 1 https://chromium.googlesource.com/external/gyp.git gyp

Add the below common.gypi file in the root of the project.

Copy the binding.gyp file to myapp.gyp and add target.type, include common.gypi and include dirs to v8 and node header files:

{
    "includes": [
        "common.gypi"
    ],
    "targets": [{
      [..]
      'type': '<(library)',
      "include_dirs" : [
       [..]
        "/path-to-node/deps/v8/include",
        "/path-to-node/deps/v8/src",
        "/path-to-node/deps/uv/include",
        "/path-to-node/deps/uv/src",
        "/path-to-node/src"
      ]
    }]
}

Finally run gyp against that file:

./gyp/gyp myapp.gyp -Dlibrary=static_library --depth=. -f xcode --generator-output=./build

Now you can open ./build/myapp.xcodeproj and inspect the code and/or attach to a Node.js process running with that library in order to debug it.

{
"conditions": [
["OS=='win'", {
"target_defaults": {
"default_configuration": "Release_x64",
"configurations": {
"Debug_Win32": {
"msvs_configuration_platform": "Win32",
},
"Debug_x64": {
"msvs_configuration_platform": "x64",
},
"Release_Win32": {
"msvs_configuration_platform": "Win32",
},
"Release_x64": {
"msvs_configuration_platform": "x64",
}
}
}
}, {
"target_defaults": {
"default_configuration": "Release",
"xcode_settings": {
},
"configurations": {
"Debug": {
"defines": [
"DEBUG"
],
"xcode_settings": {
"GCC_OPTIMIZATION_LEVEL": "0",
"GCC_GENERATE_DEBUGGING_SYMBOLS": "YES"
}
},
"Release": {
"defines": [
"NDEBUG"
],
"xcode_settings": {
"GCC_OPTIMIZATION_LEVEL": "3",
"GCC_GENERATE_DEBUGGING_SYMBOLS": "NO",
"DEAD_CODE_STRIPPING": "YES",
"GCC_INLINES_ARE_PRIVATE_EXTERN": "YES"
}
}
}
}
}]
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment