GithubHelp home page GithubHelp logo

autogypi's Introduction

autogypi

build status dependency status npm version

autogypi handles issues with C++ libraries published on npm. It generates required compiler and node-gyp options for you and works great with nbind.

node-gyp is very good at fixing relative paths between .gypi files in different locations, but it cannot automatically find other npm packages, which may have been installed globally or in a node_modules directory higher up in the directory tree or hidden inside another package. autogypi deals with them.

Features

  • Initialize configuration for a node-gyp -based project.
  • Generate C++ compiler options.
  • Guess include directories to use headers from other packages.
  • Include additional .gypi files required by other packages.

Usage

Installation

Add in the scripts section of your package.json:

  "scripts": {
    "autogypi": "autogypi",
    "node-gyp": "node-gyp",

    "install": "autogypi && node-gyp configure build"
  }

Then run the commands:

npm install --save autogypi

Configuring node-gyp

You should add auto-top.gypi in the in the includes section at the top level of your binding.gyp file and auto.gypi in the includes section of each target inside.

If you don't have a binding.gyp file yet, you can create one now with the required changes already made. For example:

npm run -- autogypi --init-gyp -p nbind -s example.cc

Replace example.cc with the name of your C++ source file. You can add multiple -s options, one for each source file.

The -p nbind option means the C++ code uses a package called nbind. Multiple -p options can be added to add any other packages compatible with autogypi.

The above command creates two files with contents:

binding.gyp

{
  "targets": [
    {
      "includes": [
        "auto.gypi"
      ],
      "sources": [
        "example.cc"
      ]
    }
  ],
  "includes": [
    "auto-top.gypi"
  ]
}

autogypi.json

{
  "dependencies": [
    "nbind"
  ],
  "includes": []
}

It also prints an error if the packages you listed as dependencies are missing. For example you can install nbind and run autogypi again:

npm install --save nbind
npm run autogypi

Compiling your project

Call autogypi and node-gyp from the install script in your package.json file, for example like autogypi && node-gyp configure build or from the command line: npm run autogypi && npm run node-gyp configure build

autogypi generates two .gypi files according to its configuration. For example with only nbind as a dependency they look like:

auto-top.gypi

{
  "includes": [
    "node_modules/nbind/src/nbind-common.gypi"
  ]
}

auto.gypi

{
  "include_dirs": [
    "node_modules/nbind/node_modules/nan"
  ],
  "includes": [
    "node_modules/nbind/src/nbind.gypi"
  ]
}

Publishing a C++ library on npm

Packages should include an autogypi.json file in their root directory if they require or are intended to be used by other modules. They should list any .gypi files of their own that are required to compile or use the module. For example:

{
  "dependencies": [
    "nan"
  ],
  "includes": [
    "example.gypi"
  ]
}

The example.gypi file would then contain any gyp settings required to successfully compile and include it in other packages.

Modules without any autogypi.json file get their root directory added to include_dirs. This is enough to successfully use the nan module. More heuristics may be added later if needed.

Command line options

Run npm run -- autogypi --help to see the command line options:

  Usage: autogypi [options]

  Generate node-gyp dependency files.

  Options:

    -h, --help                output usage information
    -V, --version             output the version number
    -r, --root <path>         root path for config files, default is shell working directory
    -c, --config <path>       config file, default autogypi.json
    -o, --output <path>       per-target gypi file to create, default auto.gypi
    -t, --output-top <path>   top-level gypi file to create, default auto-top.gypi
    -T, --no-output-top       omit top-level gypi file
    -p, --package <path>      add dependency on another npm package
    -I, --include-dir <path>  add include directory for header files
    --save [flag]             save changes to config file
    --init-gyp [path]         create gyp file (default binding.gyp, implies --save) with options:
    -s, --source <path>         - add C or C++ source file

Renaming autogypi.json, auto.gypi and auto-top.gypi using the relevant command line parameters will affect generating the .gypi files and also the contents of any binding.gyp generated using the --init-gyp option.

API

Docs generated using docts

Interface AutogypiConfig

Format of autogypi.json files published in Node.js modules.
Source code: <>

Properties:

.dependencies? string[]
List of required Node.js modules.
.includes? string[]
Additional gypi files to include inside relevant targets.
.topIncludes? string[]
Additional gypi files to include at top level.
.output? string
Path to auto.gypi to generate.
.outputTop? string
Path to auto-top.gypi to generate.

Interface BindingConfig

Options for generating an initial binding.gyp file.
Source code: <>

Properties:

.basePath string
Directory where the binding.gyp will be stored.
.outputPath string
Absolute path to generated auto.gypi to include in default target.
.outputTopPath string
Absolute path to generated auto-top.gypi to include at top level.
.sourceList string[]
List of absolute paths to C/C++ source files to compile.

Interface GenerateOptions

General options for generating gypi files.
Source code: <>

Properties:

.configPath string
Absolute path to autogypi.json.
.outputPath string
Absolute path to auto.gypi to generate.
.outputTopPath string
Absolute path to auto-top.gypi to generate.

Function generate

Write auto.gypi and auto-top.gypi files according to config.
Source code: <>

generate( ) Bluebird<{}[]> <>
 ▪ opts GenerateOptions
 ▪ config AutogypiConfig Contents of autogypi.json.

Function initGyp

Return an object with contents for an initial binding.gyp file.
Source code: <>

initGyp( ) any <>
 ▪ opts BindingConfig

Function writeJson

Save pretty-printed JSON object to a file or print an appropriate error.
Source code: <>

writeJson( ) Bluebird<{}> <>
 ▪ outputPath string
 ▪ json any
 ▫ name? string
 ▫ header? string

License

The MIT License Copyright (c) 2015-2016 BusFaster Ltd

autogypi's People

Contributors

jjrv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

sportsbitenews

autogypi's Issues

Failed to execute command autogypi (npm install)

Failed to execute the command on my ubuntu 17.04 box
autogypi -r build && node-gyp -C build/asmjs configure build --asmjs=1 && copyasm build/asmjs dist

gyp ERR! build error
gyp ERR! stack Error: 'make' failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/home/bruno/nbind-example-universal/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:12)
gyp ERR! System Linux 4.10.0-22-generic
gyp ERR! command "/usr/bin/nodejs" "/home/bruno/nbind-example-universal/node_modules/.bin/node-gyp" "-C" "build/asmjs" "configure" "build" "--asmjs=1"
gyp ERR! cwd /home/bruno/nbind-example-universal/build/asmjs
gyp ERR! node -v v4.7.2
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! Linux 4.10.0-22-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "build:asmjs"
npm ERR! node v4.7.2
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! [email protected] build:asmjs: 'autogypi -r build && node-gyp -C build/asmjs configure build --asmjs=1 && copyasm build/asmjs dist'
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build:asmjs script 'autogypi -r build && node-gyp -C build/asmjs configure build --asmjs=1 && copyasm build/asmjs dist'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the nbind-example-universal package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! autogypi -r build && node-gyp -C build/asmjs configure build --asmjs=1 && copyasm build/asmjs dist
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs nbind-example-universal
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls nbind-example-universal
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request: npm ERR! /home/bruno/nbind-example-universal/npm-debug.log Warning: problems with asm.js build

Please document minimum npm version

Thanks for sharing this. When I tried npm install on nbind I got the following error:

npm ERR! unpack Could not read data for @lib/[email protected]

When I did npm update -g npm the problem went away. Old npm version was 2.11.3 (I got a new system recently) and my new npm version is 2.14.2.

Upgrade resolve to 1.9.0

Hi @jjrv do you see a reason to not upgrade the resolve dependency from ~1.1.7 to ~1.9.0?

I am looking for to use the resolve normalize-options pseudo hook feature available on version 1.9.0

The use case is to be able to compile yoga-layout using yarn pnp node resolution strategy.

After some research it looks like the reason why it is not possible currently is because yoga-layout uses autogypi which uses a version of resolve which doesn't let yarn define a custom normalize-options hook.

My workaround so far is to force a specific yarn resolution on my package.json

"resolutions": {
    "resolve": "1.9.0"
}

Curious to hear your thoughts, thank you!

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.