Compare commits
No commits in common. "main" and "gh-pages" have entirely different histories.
@ -1,6 +0,0 @@
|
||||
[alias]
|
||||
# Neon defines mutually exclusive feature flags which prevents using `cargo clippy --all-features`
|
||||
# The following aliases simplify linting the entire workspace
|
||||
clippy-legacy = "clippy --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p tests -p static_tests --features event-handler-api,proc-macros,try-catch-api,legacy-runtime -- -A clippy::missing_safety_doc"
|
||||
clippy-napi = "clippy --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p electron-tests -p napi-tests --features proc-macros,try-catch-api,napi-experimental -- -A clippy::missing_safety_doc"
|
||||
neon-test = "test --no-default-features --features napi-experimental"
|
||||
@ -1,18 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.rs]
|
||||
indent_size = 4
|
||||
|
||||
[*.toml]
|
||||
indent_size = 4
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
39
.github/workflows/lint.yml
vendored
39
.github/workflows/lint.yml
vendored
@ -1,39 +0,0 @@
|
||||
name: Lints
|
||||
|
||||
on:
|
||||
push:
|
||||
# Prevent duplicate runs of this workflow on our own internal PRs.
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [14.x]
|
||||
rust-toolchain: [nightly]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Rust ${{ matrix.rust-toolchain }}
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.rust-toolchain }}
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: install build-essential
|
||||
run: sudo apt-get install -y build-essential
|
||||
- name: Formatting
|
||||
run: cargo fmt --all -- --check
|
||||
- name: Clippy (N-API)
|
||||
run: cargo clippy-napi
|
||||
- name: Clippy (Legacy)
|
||||
run: cargo clippy-legacy
|
||||
38
.github/workflows/linux.yml
vendored
38
.github/workflows/linux.yml
vendored
@ -1,38 +0,0 @@
|
||||
name: Test on Linux
|
||||
|
||||
on:
|
||||
push:
|
||||
# Prevent duplicate runs of this workflow on our own internal PRs.
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x, 14.x, 16.x]
|
||||
rust-toolchain: [stable, beta, nightly]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Rust ${{ matrix.rust-toolchain }}
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.rust-toolchain }}
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: install build-essential
|
||||
run: sudo apt-get install -y build-essential
|
||||
- name: run cargo test
|
||||
run: xvfb-run --auto-servernum cargo neon-test -- --nocapture
|
||||
- name: run CLI test
|
||||
working-directory: ./create-neon
|
||||
run: npm test
|
||||
40
.github/workflows/macos.yml
vendored
40
.github/workflows/macos.yml
vendored
@ -1,40 +0,0 @@
|
||||
name: Test on MacOS
|
||||
|
||||
on:
|
||||
push:
|
||||
# Prevent duplicate runs of this workflow on our own internal PRs.
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: macos-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x, 14.x, 16.x]
|
||||
rust-toolchain: [stable, beta, nightly]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Rust ${{ matrix.rust-toolchain }}
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.rust-toolchain }}
|
||||
target: x86_64-apple-darwin
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
# - name: update node-gyp to latest
|
||||
# # https://github.com/nodejs/node-gyp/issues/1933#issuecomment-586915535
|
||||
# run: npm install -g node-gyp@latest
|
||||
- name: run cargo test
|
||||
run: cargo neon-test
|
||||
- name: run CLI test
|
||||
working-directory: ./create-neon
|
||||
run: npm test
|
||||
51
.github/workflows/windows.yml
vendored
51
.github/workflows/windows.yml
vendored
@ -1,51 +0,0 @@
|
||||
name: Test on Windows
|
||||
|
||||
on:
|
||||
push:
|
||||
# Prevent duplicate runs of this workflow on our own internal PRs.
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: windows-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x, 14.x, 16.x]
|
||||
rust-toolchain: [stable, beta, nightly]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Rust ${{ matrix.rust-toolchain }}
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.rust-toolchain }}
|
||||
target: x86_64-pc-windows-msvc
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: Use npm v6
|
||||
if: ${{ matrix.node-version == '16.x' }}
|
||||
run: npm install -g npm@6
|
||||
- name: Install libclang
|
||||
uses: KyleMayes/install-llvm-action@01144dc97b1e2693196c3056414a44f15180648b
|
||||
with:
|
||||
version: "10"
|
||||
directory: ${{ runner.temp }}/llvm
|
||||
# - name: update node-gyp to latest
|
||||
# # https://github.com/nodejs/node-gyp/issues/1933#issuecomment-586915535
|
||||
# run: npm install -g node-gyp@latest
|
||||
- run: npm config set msvs_version 2019
|
||||
- name: run cargo test
|
||||
run: cargo neon-test
|
||||
env:
|
||||
LIBCLANG_PATH: ${{ runner.temp }}/llvm/bin
|
||||
- name: run CLI test
|
||||
working-directory: ./create-neon
|
||||
run: npm test
|
||||
15
.gitignore
vendored
15
.gitignore
vendored
@ -1,15 +0,0 @@
|
||||
target
|
||||
Cargo.lock
|
||||
**/*~
|
||||
**/node_modules
|
||||
**/.DS_Store
|
||||
**/build
|
||||
**/index.node
|
||||
**/artifacts.json
|
||||
cli/lib
|
||||
create-neon/dist
|
||||
create-neon/create-neon-test-project
|
||||
create-neon/create-neon-manual-test-project
|
||||
test/cli/lib
|
||||
npm-debug.log
|
||||
rls*.log
|
||||
62
AUTHORS.md
62
AUTHORS.md
@ -1,62 +0,0 @@
|
||||
# Authors
|
||||
|
||||
Neon owes its existence to the contributions of these fine people.
|
||||
|
||||
* [Reza Akhavan](https://github.com/jedireza)
|
||||
* [Nerijus Arlauskas](https://github.com/Nercury)
|
||||
* [Igor Artamonov](https://github.com/splix)
|
||||
* [Peter Atashian](https://github.com/retep998)
|
||||
* [David Baker](https://github.com/dbkr)
|
||||
* [Sean Billig](https://github.com/sbillig)
|
||||
* [Tim Blair](https://github.com/tblair)
|
||||
* [Max Brunsfeld](https://github.com/maxbrunsfeld)
|
||||
* [Dale Bustad](https://github.com/divmain)
|
||||
* [Eduard-Mihai Burtescu](https://github.com/eddyb)
|
||||
* [Gabriel Castro](https://github.com/GabrielCastro)
|
||||
* [Lin Clark](https://github.com/linclark)
|
||||
* [Nathaniel Daniel](https://github.com/adumbidiot)
|
||||
* [Joey Ezechiëls](https://github.com/jjpe)
|
||||
* [Cory Forsyth](https://github.com/bantic)
|
||||
* [Olivier Goffart](https://github.com/ogoffart)
|
||||
* [Dave Herman](https://github.com/dherman)
|
||||
* [Himself65](https://github.com/Himself65)
|
||||
* [Maciej Hirsz](https://github.com/maciejhirsz)
|
||||
* [Amal Hussein](https://github.com/nomadtechie)
|
||||
* [Usagi Ito](https://github.com/usagi)
|
||||
* [Jeroen (jrd-rocks)](https://github.com/jrd-rocks)
|
||||
* [Keegan (mhsjlw)](https://github.com/mhsjlw)
|
||||
* [Florian Keller](https://github.com/ffflorian)
|
||||
* [Aleksey Kladov](https://github.com/matklad)
|
||||
* [Adam Kloboucnik](https://github.com/akloboucnik)
|
||||
* [Renée Kooi](https://github.com/goto-bus-stop)
|
||||
* [Anton Lazarev](https://github.com/antonok-edm)
|
||||
* [Simon Liang](https://github.com/lhr0909)
|
||||
* [Terence Lee](https://github.com/hone)
|
||||
* [Milan Loveless](https://github.com/MilanLoveless)
|
||||
* [Darin Morrison](https://github.com/freebroccolo)
|
||||
* [Martin Muñoz](https://github.com/mmun)
|
||||
* [Kayo Phoenix](https://github.com/katyo)
|
||||
* [Mike Piccolo](https://github.com/mfpiccolo)
|
||||
* [Robbie Pitts](https://github.com/robbiepitts)
|
||||
* [Thiago Pontes](https://github.com/thiagopnts)
|
||||
* [Sean Prashad](https://github.com/SeanPrashad)
|
||||
* [Jordan Rose](https://github.com/jrose-signal)
|
||||
* [Antonio Scandurra](https://github.com/as-cii)
|
||||
* [Edward Shaw](https://github.com/EdShaw)
|
||||
* [Nathan Sobo](https://github.com/nathansobo)
|
||||
* [André Staltz](https://github.com/staltz)
|
||||
* [Ingvar Stepanyan](https://github.com/RReverser)
|
||||
* [stoically](https://github.com/stoically)
|
||||
* [Andrew Stucki](https://github.com/andrewstucki)
|
||||
* [Martin Svanberg](https://github.com/msvbg)
|
||||
* [A2ZH (theJian)](https://github.com/theJian)
|
||||
* [Corbin Uselton](https://github.com/corbinu)
|
||||
* [K.J. Valencik](https://github.com/kjvalencik)
|
||||
* [Velithris](https://github.com/Zireael-N)
|
||||
* [Roberto Vidal](https://github.com/jrvidal)
|
||||
* [Georg Vienna](https://github.com/geovie)
|
||||
* [Daijiro Wachi](https://github.com/watilde)
|
||||
* [Chi Wang](https://github.com/patr0nus)
|
||||
* [wangcong](https://github.com/king6cong)
|
||||
* [Amila Welihinda](https://github.com/amilajack)
|
||||
* [Felix Yan](https://github.com/felixonmars)
|
||||
@ -1,74 +0,0 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at david.herman@gmail.com. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
# Contributing to Neon
|
||||
|
||||
Neon welcomes contribution from everyone. Here are some resources to help you join us!
|
||||
|
||||
## Contributions
|
||||
|
||||
### Issue reports
|
||||
|
||||
We welcome issues and aim to keep the barrier low. Just [file a GitHub issue](https://github.com/neon-bindings/neon/issues)
|
||||
like normal---we don't require issue templates or have any particular process.
|
||||
|
||||
That said, the more information you can provide to help us reproduce your issue, the better!
|
||||
|
||||
### Requests For Comments
|
||||
|
||||
If you would like to propose a design change or new feature for the Neon API or the `neon` command-line tool,
|
||||
we encourage you to [submit an RFC](https://github.com/neon-bindings/rfcs)!
|
||||
|
||||
The [RFC process](https://github.com/neon-bindings/rfcs#the-process) has a little more overhead than
|
||||
filing an issue, but it's for the goal of allowing the Neon community to have a chance to vet
|
||||
design ideas and reach consensus. And even at that, we've deliberately kept the [RFC template](https://github.com/neon-bindings/rfcs/blob/main/0000-template.md)
|
||||
simple and open-ended.
|
||||
|
||||
### Good first bugs
|
||||
|
||||
Search our issue tracker for anything labeled **[beginner friendly](https://github.com/neon-bindings/neon/issues?q=is%3Aissue+is%3Aopen+label%3A%22beginner+friendly%22)**.
|
||||
|
||||
**We are here to help you!** Join our Slack and send an at-mention to **@dherman** and we'll happily arrange
|
||||
to help you get going and mentor you as much as you feel would be helpful.
|
||||
|
||||
## Conduct
|
||||
|
||||
We follow the [Contributor Covenant Code of Conduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html).
|
||||
The maintainers of Neon personally promise to work actively to uphold that code of conduct.
|
||||
We aim to foster a community that is welcoming, inclusive, empathetic, and kind.
|
||||
If you share those goals and want to have a ton of fun playing with Rust and JS, we hope you will come be a part of our community!
|
||||
|
||||
## License
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as described in the [README](README.md), without any additional terms or conditions.
|
||||
|
||||
## Communication
|
||||
|
||||
* Slack: <https://rust-bindings.slack.com> -- get an invite from [the Slackin app](https://rust-bindings-slackin.herokuapp.com)
|
||||
45
COPYRIGHT.txt
Normal file
45
COPYRIGHT.txt
Normal file
@ -0,0 +1,45 @@
|
||||
These documentation pages include resources by third parties. This copyright
|
||||
file applies only to those resources. The following third party resources are
|
||||
included, and carry their own copyright notices and license terms:
|
||||
|
||||
* Fira Sans (FiraSans-Regular.woff, FiraSans-Medium.woff):
|
||||
|
||||
Copyright (c) 2014, Mozilla Foundation https://mozilla.org/
|
||||
with Reserved Font Name Fira Sans.
|
||||
|
||||
Copyright (c) 2014, Telefonica S.A.
|
||||
|
||||
Licensed under the SIL Open Font License, Version 1.1.
|
||||
See FiraSans-LICENSE.txt.
|
||||
|
||||
* rustdoc.css, main.js, and playpen.js:
|
||||
|
||||
Copyright 2015 The Rust Developers.
|
||||
Licensed under the Apache License, Version 2.0 (see LICENSE-APACHE.txt) or
|
||||
the MIT license (LICENSE-MIT.txt) at your option.
|
||||
|
||||
* normalize.css:
|
||||
|
||||
Copyright (c) Nicolas Gallagher and Jonathan Neal.
|
||||
Licensed under the MIT license (see LICENSE-MIT.txt).
|
||||
|
||||
* Source Code Pro (SourceCodePro-Regular.woff, SourceCodePro-Semibold.woff):
|
||||
|
||||
Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/),
|
||||
with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark
|
||||
of Adobe Systems Incorporated in the United States and/or other countries.
|
||||
|
||||
Licensed under the SIL Open Font License, Version 1.1.
|
||||
See SourceCodePro-LICENSE.txt.
|
||||
|
||||
* Source Serif Pro (SourceSerifPro-Regular.ttf.woff,
|
||||
SourceSerifPro-Bold.ttf.woff, SourceSerifPro-It.ttf.woff):
|
||||
|
||||
Copyright 2014 Adobe Systems Incorporated (http://www.adobe.com/), with
|
||||
Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of
|
||||
Adobe Systems Incorporated in the United States and/or other countries.
|
||||
|
||||
Licensed under the SIL Open Font License, Version 1.1.
|
||||
See SourceSerifPro-LICENSE.txt.
|
||||
|
||||
This copyright file is intended to be distributed with rustdoc output.
|
||||
91
Cargo.toml
91
Cargo.toml
@ -1,91 +0,0 @@
|
||||
[package]
|
||||
name = "neon"
|
||||
version = "0.8.2"
|
||||
authors = ["Dave Herman <david.herman@gmail.com>"]
|
||||
description = "A safe abstraction layer for Node.js."
|
||||
readme = "README.md"
|
||||
homepage = "https://www.neon-bindings.com"
|
||||
repository = "https://github.com/neon-bindings/neon"
|
||||
license = "MIT/Apache-2.0"
|
||||
exclude = ["neon.jpg", "doc/**/*"]
|
||||
build = "build.rs"
|
||||
edition = "2018"
|
||||
|
||||
[build-dependencies]
|
||||
neon-build = { version = "=0.8.2", path = "crates/neon-build" }
|
||||
|
||||
[dev-dependencies]
|
||||
lazy_static = "1.4.0"
|
||||
rustversion = "0.1.4"
|
||||
semver = "0.9"
|
||||
psd = "0.1.9" # used for a doc example
|
||||
failure = "0.1.5" # used for a doc example
|
||||
|
||||
[dependencies]
|
||||
cslice = "0.2"
|
||||
semver = "0.9.0"
|
||||
smallvec = "1.4.2"
|
||||
neon-runtime = { version = "=0.8.2", path = "crates/neon-runtime" }
|
||||
neon-macros = { version = "=0.8.2", path = "crates/neon-macros", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["legacy-runtime"]
|
||||
|
||||
# Enable static tests. These can be fragile because of variations in Rust compiler
|
||||
# error message formatting from version to version, so they're disabled by default.
|
||||
enable-static-tests = []
|
||||
|
||||
# Enable the EventHandler API of RFC 25.
|
||||
event-handler-api = []
|
||||
|
||||
# Enable the default panic hook. Useful for debugging neon itself.
|
||||
default-panic-hook = []
|
||||
|
||||
# Feature flag to enable the legacy V8/NAN runtime. For now, this feature is
|
||||
# enabled by default.
|
||||
legacy-runtime = ["neon-runtime/neon-sys", "neon-build/neon-sys"]
|
||||
|
||||
# Default N-API version. Prefer to select a minimum required version.
|
||||
napi-runtime = ["napi-6"]
|
||||
|
||||
# Select the N-API version
|
||||
# Feature flags to enable the experimental N-API runtime. For now, this feature
|
||||
# is disabled by default.
|
||||
# The Node N-API documentation specifies N-API and Node version requirements
|
||||
# https://nodejs.org/api/n-api.html
|
||||
napi-1 = ["proc-macros", "neon-macros/napi", "neon-runtime/napi"]
|
||||
napi-2 = ["napi-1", "neon-runtime/napi-2"]
|
||||
napi-3 = ["napi-2", "neon-runtime/napi-3"]
|
||||
napi-4 = ["napi-3", "neon-runtime/napi-4"]
|
||||
napi-5 = ["napi-4", "neon-runtime/napi-5"]
|
||||
napi-6 = ["napi-5", "neon-runtime/napi-6"]
|
||||
napi-latest = ["napi-6"]
|
||||
napi-experimental = ["napi-6", "neon-runtime/napi-experimental"]
|
||||
|
||||
# Feature flag to disable external dependencies on docs build
|
||||
docs-only = ["neon-runtime/docs-only"]
|
||||
|
||||
# Feature flag to enable the try_catch API of RFC 29.
|
||||
try-catch-api = []
|
||||
|
||||
# Feature flag to enable the `EventQueue` API of RFC 33.
|
||||
# https://github.com/neon-bindings/rfcs/pull/32
|
||||
event-queue-api = []
|
||||
|
||||
# Feature flag to include procedural macros
|
||||
proc-macros = ["neon-macros"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = ["docs-only", "event-handler-api", "proc-macros", "try-catch-api"]
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"crates/neon-build",
|
||||
"crates/neon-macros",
|
||||
"crates/neon-runtime",
|
||||
"crates/neon-sys",
|
||||
"test/static",
|
||||
"test/electron",
|
||||
"test/dynamic/native",
|
||||
"test/napi"
|
||||
]
|
||||
94
FiraSans-LICENSE.txt
Normal file
94
FiraSans-LICENSE.txt
Normal file
@ -0,0 +1,94 @@
|
||||
Digitized data copyright (c) 2012-2015, The Mozilla Foundation and Telefonica S.A.
|
||||
with Reserved Font Name < Fira >,
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
BIN
FiraSans-Medium.woff
Normal file
BIN
FiraSans-Medium.woff
Normal file
Binary file not shown.
BIN
FiraSans-Regular.woff
Normal file
BIN
FiraSans-Regular.woff
Normal file
Binary file not shown.
BIN
Heuristica-Italic.woff
Normal file
BIN
Heuristica-Italic.woff
Normal file
Binary file not shown.
101
Heuristica-LICENSE.txt
Normal file
101
Heuristica-LICENSE.txt
Normal file
@ -0,0 +1,101 @@
|
||||
Copyright 1989, 1991 Adobe Systems Incorporated. All rights reserved.
|
||||
Utopia is either a registered trademark or trademark of Adobe Systems
|
||||
Incorporated in the United States and/or other countries. Used under
|
||||
license.
|
||||
|
||||
Copyright 2006 Han The Thanh, Vntopia font family, http://vntex.sf.net
|
||||
|
||||
Copyright (c) 2008-2012, Andrey V. Panov (panov@canopus.iacp.dvo.ru),
|
||||
with Reserved Font Name Heuristica.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
19
LICENSE-MIT
19
LICENSE-MIT
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2015 David Herman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
23
LICENSE-MIT.txt
Normal file
23
LICENSE-MIT.txt
Normal file
@ -0,0 +1,23 @@
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
@ -1,320 +0,0 @@
|
||||
# N-API Migration Guide
|
||||
|
||||
## What is this about?
|
||||
|
||||
Since v10, Node.js supports an improved API for building native modules, known as [N-API](https://nodejs.org/api/n-api.html). N-API offers a clearer, more complete, and more stable API layer for writing Node.js plugins than previous Node versions did.
|
||||
|
||||
The Neon community has been [hard at work](https://github.com/neon-bindings/neon/issues/444) porting the library to a new backend based on N-API.
|
||||
|
||||
### Why N-API?
|
||||
|
||||
Some key benefits of the new backend include:
|
||||
- Compiled Neon modules will work in all versions of Node _without needing to be recompiled_, guaranteed!
|
||||
- You can precompile Neon-based libraries to be completely transparent to downstream consumers.
|
||||
- The build process is streamlined, making Neon apps more reliable and easier to debug.
|
||||
- The stability guarantees of N-API allow us to avoid risk of incompatible changes to future releases of Neon.
|
||||
|
||||
### What does this mean for me?
|
||||
|
||||
Porting Neon to N-API has been mostly transparent, but it has required a few backwards-incompatible changes. This guide provides instructions on how to migrate existing apps to the new N-API backend.
|
||||
|
||||
Fortunately, the guaranteed stability of N-API means that once Neon users do this migration, we have increased confidence in the stability of Neon. We expect this to be the **last major breaking change before reaching Neon 1.0.**
|
||||
|
||||
If you have any trouble porting, **please reach out to us** with a Neon issue or on the community Slack! We want to help everyone upgrade as smoothly and seamlessly as possible.
|
||||
|
||||
|
||||
## Getting started
|
||||
|
||||
### Supported Node versions
|
||||
|
||||
The N-API backend of Neon requires a minimum Node version of 10.0.
|
||||
|
||||
### Enabling the N-API backend
|
||||
|
||||
To enable the N-API backend, you need to:
|
||||
|
||||
1. Remove `build.rs` from the project directory and `build = "build.rs"` from the `Cargo.toml`. The N-API backend does not require a Cargo build script.
|
||||
2. Disable the default features (for now, the default features select the legacy backend) by setting `default-features = false`; and
|
||||
3. Enable the appropriate feature flag in your `Cargo.toml` to select the N-API version you need support for (each N-API version N uses the feature flag `"napi-N"`, for example `"napi-4"` for N-API version 4).
|
||||
|
||||
As a rule, you should choose the **oldest version of N-API that has the APIs you need.** (We will be adding N-API version requirements to the Neon API docs to make this clearer in the future.) You can consult the [official N-API feature matrix](https://nodejs.org/api/n-api.html#n_api_node_api_version_matrix) to see which N-API versions come with various versions of Node.
|
||||
|
||||
```toml
|
||||
[dependencies.neon]
|
||||
version = "0.8.2"
|
||||
default-features = false
|
||||
features = ["napi-4"]
|
||||
```
|
||||
|
||||
|
||||
## Minor API changes
|
||||
|
||||
### Context
|
||||
|
||||
Many methods that previously did not require context (e.g., `JsString::size`) now require a context. In many cases, this means adding an additional argument or using a convenience method on the `Context` trait.
|
||||
|
||||
#### Affected methods
|
||||
|
||||
##### Handle
|
||||
|
||||
* `Handle`
|
||||
- `is_a`
|
||||
- `downcast`
|
||||
|
||||
`Handle::downcast` also requires a second type argument for the context type. This can usually be inferred, so you can typically use `_`.
|
||||
|
||||
**Before:**
|
||||
```rust
|
||||
value.downcast::<JsNumber>()
|
||||
```
|
||||
|
||||
**After:**
|
||||
|
||||
```rust
|
||||
value.downcast::<JsNumber, _>(&mut cx)
|
||||
```
|
||||
|
||||
##### Primitive types
|
||||
|
||||
* `JsBoolean`
|
||||
- `value`
|
||||
* `JsNull`
|
||||
- `new`
|
||||
* `JsString`
|
||||
- `size`
|
||||
- `value`
|
||||
* `JsNumber`
|
||||
- `value`
|
||||
* `JsUndefined`
|
||||
- `new`
|
||||
|
||||
##### Object APIs
|
||||
|
||||
* `PropertyKey`
|
||||
- `get_from`
|
||||
- `set_from`
|
||||
|
||||
### Handle equality
|
||||
|
||||
Handles no longer implement `Eq` or `PartialEq`, which had underspecified behavior. Use `Value::strict_equals` instead to invoke the behavior of JavaScript's `===` operator.
|
||||
|
||||
## Major API changes
|
||||
|
||||
The N-API backend introduces two categories of significant change:
|
||||
|
||||
1. Embedding Rust data, which is no longer done through the awkward and complex `declare_types!` (i.e. classes) macro, but through a simpler primitive: the `JsBox` API.
|
||||
2. Concurrency, which is offered through the Event Queue API instead of the Task API or Event Handlers, both of which are deprecated and removed in the N-API backend.
|
||||
|
||||
### Embedding Rust data
|
||||
|
||||
The `declare_types!` macro is deprecated and replaced by the `JsBox` type.
|
||||
|
||||
_Rationale:_ The `declare_types!` macro provides a syntax for defining classes, but requires substantial boilerplate and is unergonomic for simple cases and tends to interact poorly with IDEs. It's also not flexible enough to express the full range of JavaScript classes syntax and semantics. With the `JsBox` type, it's easy to embed Rust data in JavaScript objects, which can then be nested inside of more feature-rich classes defined in pure JavaScript (or TypeScript).
|
||||
|
||||
**Before:**
|
||||
|
||||
```rust
|
||||
struct User {
|
||||
first_name: String,
|
||||
last_name: String,
|
||||
}
|
||||
|
||||
impl User {
|
||||
fn full_name(&self) -> String {
|
||||
format!("{} {}", self.first_name, self.last_name)
|
||||
}
|
||||
}
|
||||
|
||||
declare_types! {
|
||||
class JsUser for User {
|
||||
init(mut cx) {
|
||||
let first_name = cx.argument::<JsString>(0)?;
|
||||
let last_name = cx.argument::<JsString>(1)?;
|
||||
Ok(User { first_name, last_name })
|
||||
}
|
||||
|
||||
method full_name(mut cx) {
|
||||
let this = cx.this();
|
||||
let guard = cx.lock();
|
||||
let user = this.borrow(&guard);
|
||||
let full_name = user.full_name();
|
||||
Ok(cx.string(full_name).upcast())
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**After:**
|
||||
|
||||
On the Rust side, the wrapped type must implement the `Finalize` trait, but this comes with a default implementation so it can be implemented with an empty `impl` block:
|
||||
|
||||
```rust
|
||||
struct User {
|
||||
first_name: String,
|
||||
last_name: String,
|
||||
}
|
||||
|
||||
impl Finalize for User { }
|
||||
```
|
||||
|
||||
The type can then be exposed to JavaScript with simple functions that wrap `User` in a `JsBox`:
|
||||
|
||||
```rust
|
||||
fn create_user(mut cx: FunctionContext) -> JsResult<JsBox<User>> {
|
||||
let first_name = cx.argument::<JsString>(0)?.value(&mut cx);
|
||||
let last_name = cx.argument::<JsString>(1)?.value(&mut cx);
|
||||
Ok(cx.boxed(User { first_name, last_name }))
|
||||
}
|
||||
|
||||
fn user_full_name(mut cx: FunctionContext) -> JsResult<JsString> {
|
||||
let user = cx.argument::<JsBox<User>>(0)?;
|
||||
let full_name = user.full_name();
|
||||
Ok(cx.string(full_name))
|
||||
}
|
||||
```
|
||||
|
||||
Finally, you can provide an idiomatic JavaScript interface to the type by wrapping the boxed type in a class:
|
||||
|
||||
```js
|
||||
class User {
|
||||
constructor(firstName, lastName) {
|
||||
this.boxed = addon.createUser(firstName, lastName);
|
||||
}
|
||||
|
||||
fullName() {
|
||||
return addon.userFullName(this.boxed);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Concurrency
|
||||
|
||||
The supported mechanism for concurrency is the Event Queue API (`neon::event::EventQueue`). This feature has not yet stabilized, so to use this API, you'll also need to enable the `"event-queue-api"` feature flag as well:
|
||||
|
||||
```toml
|
||||
[dependencies.neon]
|
||||
version = "0.8.1"
|
||||
default-features = false
|
||||
features = ["napi-4", "event-queue-api"]
|
||||
```
|
||||
|
||||
#### Deprecated: Task API
|
||||
|
||||
The Task API (`neon::task`) is deprecated, and should in most cases be translated to using the Event Queue API.
|
||||
|
||||
_Rationale:_ The Task API was built on top of the low-level libuv thread pool, which manages the concurrency of the Node.js system internals and should rarely be exposed to user-level programs. For most use cases, Neon users took advantage of this API as the only way to implement background, asynchronous computations. The Event Queue API is a more general-purpose, convenient, and safe way of achieving that purpose.
|
||||
|
||||
That said, **if you believe you need access to the libuv thread pool, please [file an issue in the Neon repository](https://github.com/neon-bindings/neon/issues) with a description of your use case to let us know about it.** We don't believe this is commonly needed, but we don't want to leave you stuck!
|
||||
|
||||
**Before:**
|
||||
|
||||
With the `Task` API it was possible to define background computations off the main JavaScript thread, but these could only be run within the libuv thread pool--which runs all the system logic for the internals of Node.js. This gave Neon programmers a real power but forced them to contend with Node.js system tasks.
|
||||
|
||||
```rust
|
||||
impl Task for MyTask {
|
||||
type Output = i32;
|
||||
type Error = String;
|
||||
type JsEvent = JsNumber;
|
||||
|
||||
fn perform(&self) -> Result<Self::Output, Self::Error> {
|
||||
// compute the result...
|
||||
}
|
||||
|
||||
fn complete(self, mut cx: TaskContext, result: Result<Self::Output, Self::Error>) -> JsResult<Self::JsEvent> {
|
||||
match result {
|
||||
Ok(n) => {
|
||||
Ok(cx.number(n))
|
||||
}
|
||||
Err(s) => {
|
||||
cx.throw_error(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_task(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
||||
let callback = cx.argument::<JsFunction>(0)?;
|
||||
MyTask.schedule(callback);
|
||||
Ok(cx.undefined())
|
||||
}
|
||||
```
|
||||
|
||||
**After:**
|
||||
|
||||
With the N-API backend, Neon programmers can use their own native threads and avoid competing with the Node.js system internals. This also brings some convenience since it doesn't require defining any custom trait implementations.
|
||||
|
||||
```rust
|
||||
pub fn start_task(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
||||
let callback = cx.argument::<JsFunction>(0)?.root(&mut cx);
|
||||
let queue = cx.queue();
|
||||
|
||||
std::thread::spawn(move || {
|
||||
let result = // compute the result...
|
||||
queue.send(move |mut cx| {
|
||||
let callback = callback.into_inner(&mut cx);
|
||||
let this = cx.undefined();
|
||||
let args = match result {
|
||||
Ok(n) => vec![
|
||||
cx.null().upcast::<JsValue>(),
|
||||
cx.number(result).upcast()
|
||||
],
|
||||
Err(msg) => vec![
|
||||
cx.error(msg).upcast()
|
||||
]
|
||||
};
|
||||
callback.call(&mut cx, this, args)?;
|
||||
Ok(())
|
||||
});
|
||||
});
|
||||
|
||||
Ok(cx.undefined())
|
||||
}
|
||||
```
|
||||
|
||||
#### Deprecated: Event Handler API
|
||||
|
||||
The Event Handler API (`neon::event::EventHandler`) is deprecated and should be replaced by the Event Queue API.
|
||||
|
||||
_Rationale_: The Event Handler API had multiple issues with safety, memory leaks, and ergonomics ([1](https://github.com/neon-bindings/neon/issues/551), [2](https://github.com/neon-bindings/rfcs/issues/31)).
|
||||
|
||||
**Before:**
|
||||
|
||||
```rust
|
||||
pub fn start_task(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
||||
let callback = cx.argument::<JsFunction>(0)?;
|
||||
let handler = EventHandler::new(callback);
|
||||
thread::spawn(move || {
|
||||
let result = // compute the result...
|
||||
handler.schedule(move |cx| {
|
||||
vec![cx.number(result).upcast()]
|
||||
});
|
||||
});
|
||||
Ok(cx.undefined())
|
||||
}
|
||||
```
|
||||
|
||||
**After:**
|
||||
|
||||
```rust
|
||||
pub fn start_task(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
||||
let callback = cx.argument::<JsFunction>(0)?.root(&mut cx);
|
||||
let queue = cx.queue();
|
||||
|
||||
std::thread::spawn(move || {
|
||||
let result = // compute the result...
|
||||
queue.send(move |mut cx| {
|
||||
let callback = callback.into_inner(&mut cx);
|
||||
let this = cx.undefined();
|
||||
let args = vec![
|
||||
cx.null().upcast::<JsValue>(),
|
||||
cx.number(result).upcast()
|
||||
];
|
||||
callback.call(&mut cx, this, args)?;
|
||||
Ok(())
|
||||
});
|
||||
});
|
||||
|
||||
Ok(cx.undefined())
|
||||
}
|
||||
```
|
||||
|
||||
94
README.md
94
README.md
@ -1,94 +0,0 @@
|
||||
<img src="neon.png" alt="neon" width="100%" />
|
||||
|
||||
[](https://crates.io/crates/neon)
|
||||
[](https://www.npmjs.com/package/neon-cli)
|
||||
[](https://github.com/neon-bindings/neon/actions?query=workflow%3A%22Test+on+Linux%22)
|
||||
[](https://github.com/neon-bindings/neon/actions?query=workflow%3A%22Test+on+MacOS%22)
|
||||
[](https://github.com/neon-bindings/neon/actions?query=workflow%3A%22Test+on+Windows%22)
|
||||
|
||||
Rust bindings for writing safe and fast native Node.js modules.
|
||||
|
||||
# Getting started
|
||||
|
||||
Once you have the [platform dependencies](https://neon-bindings.com/docs/getting-started#install-node-build-tools/) installed, getting started is as simple as:
|
||||
|
||||
```
|
||||
$ npm init neon my-project
|
||||
```
|
||||
|
||||
Then see the [Hello World guide](https://neon-bindings.com/docs/hello-world/) for writing your first Hello World in Neon!
|
||||
|
||||
_**Note:** This will create a new project with the `napi-backend` and some documentation may not be up to date._
|
||||
|
||||
# Docs
|
||||
|
||||
See our [Neon fundamentals docs](https://neon-bindings.com/docs/intro) and our [API docs](https://docs.rs/neon/latest/neon).
|
||||
|
||||
# N-API Migration Guide
|
||||
|
||||
We've ported Neon to a new backend based on [N-API](https://nodejs.org/api/n-api.html), which will be the basis for Neon 1.0.
|
||||
|
||||
**Read the new [migration guide](https://github.com/neon-bindings/neon/blob/main/MIGRATION_GUIDE.md)** to learn how to port your Neon projects to N-API!
|
||||
|
||||
# Platform Support
|
||||
|
||||
### Operating Systems
|
||||
|
||||
| Linux | macOS | Windows |
|
||||
| ------ | ----- | ------- |
|
||||
| ✓ | ✓ | ✓ |
|
||||
|
||||
### Node.js
|
||||
|
||||
| Node 12 | Node 14 | Node 16 |
|
||||
| ------- | ------- | ------- |
|
||||
| ✓ | ✓ | ✓ |
|
||||
|
||||
Support for [LTS versions of Node](https://github.com/nodejs/LTS#release-schedule) and current are expected. If you're using a different version of Node and believe it should be supported, let us know.
|
||||
|
||||
### Rust
|
||||
|
||||
Neon supports Rust stable version 1.18 and higher. We test on the latest stable, beta, and nightly versions of Rust.
|
||||
|
||||
# A Taste...
|
||||
|
||||
```rust
|
||||
fn make_an_array(mut cx: FunctionContext) -> JsResult<JsArray> {
|
||||
// Create some values:
|
||||
let n = cx.number(9000);
|
||||
let s = cx.string("hello");
|
||||
let b = cx.boolean(true);
|
||||
|
||||
// Create a new array:
|
||||
let array: Handle<JsArray> = cx.empty_array();
|
||||
|
||||
// Push the values into the array:
|
||||
array.set(&mut cx, 0, n)?;
|
||||
array.set(&mut cx, 1, s)?;
|
||||
array.set(&mut cx, 2, b)?;
|
||||
|
||||
// Return the array:
|
||||
Ok(array)
|
||||
}
|
||||
|
||||
register_module!(mut cx, {
|
||||
cx.export_function("makeAnArray", make_an_array)
|
||||
})
|
||||
```
|
||||
|
||||
For more examples, see our [examples repo](https://github.com/neon-bindings/examples).
|
||||
|
||||
# Get Involved
|
||||
|
||||
The Neon community is just getting started and there's tons of fun to be had. Come play! :)
|
||||
|
||||
The [Rust Bindings community Slack](https://rust-bindings.slack.com) is open to all; use [the Slackin app](https://rust-bindings-slackin.herokuapp.com) to receive an invitation.
|
||||
|
||||
# License
|
||||
|
||||
Licensed under either of
|
||||
|
||||
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||
|
||||
at your option.
|
||||
336
RELEASES.md
336
RELEASES.md
@ -1,336 +0,0 @@
|
||||
# Version 0.8.2
|
||||
|
||||
* More docs improvements
|
||||
* Added a deprecation warning to `neon new` (https://github.com/neon-bindings/neon/pull/722)
|
||||
|
||||
# Version 0.8.1
|
||||
|
||||
* Fix `legacy-backend` for Node 16 (https://github.com/neon-bindings/neon/pull/715)
|
||||
* Various docs improvements
|
||||
|
||||
# Version 0.8.0
|
||||
|
||||
## Fixes
|
||||
|
||||
* `as_slice` and `as_mut_slice` properly handle a `null` pointer from an empty buffer (https://github.com/neon-bindings/neon/pull/681)
|
||||
* Global drop queue added to avoid panics on N-API 6+ when dropping a `Root` (https://github.com/neon-bindings/neon/pull/700)
|
||||
|
||||
## Features
|
||||
|
||||
* Added `neon::reflect::eval` (https://github.com/neon-bindings/neon/pull/692)
|
||||
* Added `create-neon` for creating an N-API project (https://github.com/neon-bindings/neon/pull/690)
|
||||
* Added details to the `README.md` generated by `create-neon` (https://github.com/neon-bindings/neon/pull/697)
|
||||
|
||||
## Improvements
|
||||
|
||||
* Switched N-API tests to `cargo-cp-artifact` (https://github.com/neon-bindings/neon/pull/687)
|
||||
* Added `impl<T: Finalize> Finalize for Option<T>` (https://github.com/neon-bindings/neon/pull/680)
|
||||
* Added a N-API migration guide (https://github.com/neon-bindings/neon/pull/685)
|
||||
|
||||
## Housekeeping
|
||||
|
||||
* Lint fixes (https://github.com/neon-bindings/neon/pull/609)
|
||||
* Lint CI enforcement and `cargo fmt` (https://github.com/neon-bindings/neon/pull/698)
|
||||
|
||||
# Version 0.7.1
|
||||
|
||||
### Features
|
||||
|
||||
* Added `JsDate` to N-API backend (https://github.com/neon-bindings/neon/pull/639)
|
||||
* Implement `JsBuffer::unitialized` for N-API backend (https://github.com/neon-bindings/neon/pull/664)
|
||||
|
||||
### Fixes
|
||||
|
||||
* Do not panic if a `Root` is leaked after the event loop has stopped (https://github.com/neon-bindings/neon/pull/677)
|
||||
* Stubs for features that will not be implemented in the N-API backend are removed (https://github.com/neon-bindings/neon/pull/663)
|
||||
* Fix doc URL link (https://github.com/neon-bindings/neon/pull/663)
|
||||
|
||||
# Version 0.7.0
|
||||
|
||||
## N-API
|
||||
|
||||
### Version Selection
|
||||
|
||||
Neon supports a large number of different Node versions which may have different N-API requirements. Neon now supports selecting the minimum required N-API version required by a module. For example, for N-API Version 4:
|
||||
|
||||
```toml
|
||||
neon = { version = "0.7", default-features = false, features = ["napi-4"] }
|
||||
```
|
||||
|
||||
If the Neon module is loaded in an older version of Node that does not support that N-API version, a `panic` message will inform the user.
|
||||
|
||||
### Threadsafe Functions
|
||||
|
||||
A prerelease version of `EventQueue` for calling into the main JavaScript thread from Rust threads can be enabled with the `event-queue-api` feature flag. The API is considered unstable and may change in the future until the [RFC](https://github.com/neon-bindings/rfcs/pull/32) is merged.
|
||||
|
||||
# Version 0.6.0
|
||||
|
||||
The `cx.try_catch(..)` API has been updated to return `T: Sized` instead of `T: Value` (https://github.com/neon-bindings/neon/pull/631). This API is strictly more powerful and allows users to return both JavaScript and Rust values from `try_catch` closures.
|
||||
|
||||
## N-API
|
||||
|
||||
* N-API symbols are now loaded dynamically (https://github.com/neon-bindings/neon/pull/646)
|
||||
* Build process for N-API is greatly simplified by leveraging dynamic loading (https://github.com/neon-bindings/neon/pull/647)
|
||||
|
||||
# Version 0.5.3
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
Upgrade `node-gyp` (https://github.com/neon-bindings/neon/pull/623)
|
||||
* Fix Windows Node 15
|
||||
* Fix Apple M1
|
||||
|
||||
## Features
|
||||
|
||||
Added `neon::main` macro as a replacement for `register_module!` (https://github.com/neon-bindings/neon/pull/636)
|
||||
|
||||
## Known Issues
|
||||
|
||||
Builds occassionally fail with Windows, Node 15 and npm 7 (https://github.com/neon-bindings/neon/issues/642)
|
||||
|
||||
# Version 0.5.2
|
||||
|
||||
## CLI
|
||||
|
||||
Added support for [additional arguments](https://github.com/neon-bindings/neon/pull/633) passed to `cargo build`. Resolves https://github.com/neon-bindings/neon/issues/471.
|
||||
|
||||
```sh
|
||||
neon build --release -- --features awesome
|
||||
```
|
||||
|
||||
## N-API
|
||||
|
||||
* Improved [arguments performance](https://github.com/neon-bindings/neon/pull/610)
|
||||
* Add [redirect and `NPM_CONFIG_DISTURL`](https://github.com/neon-bindings/neon/pull/620) support
|
||||
|
||||
# Version 0.5.1
|
||||
|
||||
## Performance
|
||||
|
||||
* `smallvec` is used for collecting arguments and yields a small performance gain when calling `JsFunction`
|
||||
|
||||
## Broader Support
|
||||
|
||||
Thanks to @staltz, neon now builds for both iOS and Android with [nodejs-mobile](https://github.com/JaneaSystems/nodejs-mobile).
|
||||
|
||||
# Version 0.5.0
|
||||
|
||||
_Re-publish_
|
||||
|
||||
Versions `0.4.1` and `0.4.2` included a breaking change in `neon-runtime`. At the time, this was considered acceptable because `neon-runtime` is considered an internal crate and not part of the public API. However, it was discovered, after publishing, that `neon-serde`, a commonly used crate in the `neon` ecosystem, contained a direct dependency on `neon-runtime`. In order to best support users, versions `0.4.1` and `0.4.2` were "yanked" and re-published as `0.5.0`.
|
||||
|
||||
Additionally, the team is working with the authors of `neon-serde` to remove the dependency on `neon-runtime` to prevent future issues.
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
* Fix stack overflow in `DowncastError` `Display` impl (https://github.com/neon-bindings/neon/pull/606)
|
||||
|
||||
# Version 0.4.2
|
||||
|
||||
_Unpublished / Yanked_
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
* Fix memory leak and race condition in `EventHandler`
|
||||
|
||||
# Version 0.4.1
|
||||
|
||||
_Unpublished / Yanked_
|
||||
|
||||
## Features
|
||||
|
||||
### Try Catch
|
||||
|
||||
Added the `cx.try_catch` API of [RFC 29](https://github.com/neon-bindings/rfcs/pull/29). This feature is behind the `try-catch-api` feature flag.
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
* Pass `async_context` to `node::MakeCallback` (https://github.com/neon-bindings/neon/pull/498)
|
||||
* Cache bust neon if node version changes (https://github.com/neon-bindings/neon/pull/388)
|
||||
* Fix debug builds in windows (https://github.com/neon-bindings/neon/pull/400)
|
||||
* Fix cross compiling architectures (https://github.com/neon-bindings/neon/pull/491)
|
||||
* Fix neon new hanging on Windows (https://github.com/neon-bindings/neon/pull/537)
|
||||
|
||||
## CI Improvements
|
||||
|
||||
The Neon Project now uses Github Actions thanks to @lhr0909! As part of this change, CI now runs on all of our supported platforms (macOS, Windows, linux) and Node versions.
|
||||
|
||||
# Version ✨0.4✨ 🎉
|
||||
|
||||
## `EventHandler` API
|
||||
|
||||
The [`EventHandler` API](https://github.com/neon-bindings/rfcs/blob/main/text/0025-event-handler.md) is a new feature for scheduling work on the javascript main thread from other threads. Big thanks to @geovie for the RFC and implementation.
|
||||
|
||||
This feature is currently _unstable_ and gated by a `event-handler-api` feature flag.
|
||||
|
||||
## Improvements
|
||||
|
||||
* New project template updated for Rust 2018
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
* Workaround for nodejs/node-gyp#1933
|
||||
* Docs build fixed
|
||||
* Temporarily disable static tests which keep breaking CI
|
||||
|
||||
## N-API
|
||||
|
||||
* Context/Isolate threading
|
||||
* Scopes
|
||||
* Strings
|
||||
* Primitive values (numbers, undefined, null, boolean)
|
||||
|
||||
# Version 0.3.3
|
||||
|
||||
Hot fix for `neon build` in projects with many dependencies.
|
||||
|
||||
# Version 0.3.2
|
||||
|
||||
## Bug fixes and Small Features
|
||||
|
||||
* Disable node module registration on test build, allowing `cargo test` to be used on neon modules
|
||||
* Added support for alternate `CARGO_TARGET_DIR` locations (e.g., workspaces)
|
||||
* Added macros to `neon::prelude` to improve ergonomics in Rust 2018
|
||||
* Link `win_delay_hook` when building with `electron-build-env`, fixing Windows Electron
|
||||
* Fixed missing `__cxa_pure_virtual` on Linux
|
||||
* Copy native files into `OUT_DIR` and build there to fix `cargo publish` and follow best practices
|
||||
* Eliminated `mem::uniitialized()` usage, reducing warnings and fixing an instance of undefined behavior
|
||||
|
||||
## Potentially Breaking
|
||||
|
||||
The macOS link arguments were moved from `neon-cli` to `neon-build`. This is more idiomatic, but makes `neon-build` _required_ for macOS builds where it was unnecessary before.
|
||||
|
||||
Since `neon-build` has been included in the project template since `0.1` this change was not deemed significant enough to warrant a major revision.
|
||||
|
||||
## N-API
|
||||
|
||||
Neon 0.3.2 lays the groundwork for the next major revision. Development of Neon against an ABI stable Node API (N-API) will occur on main.
|
||||
|
||||
* Added `legacy-runtime` and `n-api` feature flags for toggling neon runtime
|
||||
* Moved the legacy runtime to `nodejs-sys` crate
|
||||
* Stubbed required `n-api` implementation
|
||||
* Added `feature` flag to `neon-cli` to help configuring `n-api` projects
|
||||
|
||||
# Version 0.3.1
|
||||
|
||||
* Build v0.3 project templates by default in the CLI
|
||||
|
||||
# Version 0.3
|
||||
|
||||
## Breaking Changes
|
||||
|
||||
* [Removed support for Node 6](https://github.com/neon-bindings/neon/pull/420)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
* Correctly fail the build if [custom build command fails](https://github.com/neon-bindings/neon/pull/421)
|
||||
* Fix breaking changes with v8 [`GetFunction`](https://github.com/neon-bindings/neon/pull/410)
|
||||
* Moved `nan` from `devDependencies` to `dependencies` in [`neon-runtime`](https://github.com/neon-bindings/neon/pull/367)
|
||||
* Changed neon [crate type](https://github.com/neon-bindings/neon/pull/358) from `dylib` to `cdylib`
|
||||
* Ensure that neon module loading is [not optimized away](https://github.com/neon-bindings/neon/pull/392)
|
||||
|
||||
## Improvements
|
||||
|
||||
* Added support for [`CARGO_BUILD_TARGET` environment variable](https://github.com/neon-bindings/neon/pull/411)
|
||||
|
||||
# Version ✨0.2✨ 🎉
|
||||
|
||||
See the [Neon 0.2 Migration Guide](https://github.com/neon-bindings/neon/wiki/Neon-0.2-Migration-Guide) for documentation on migrating your projects from the Neon 0.1.x series to Neon 0.2, and please [let us know](https://github.com/neon-bindings/neon#get-involved) if you need help!
|
||||
|
||||
* Release automation (#318)
|
||||
* New `ArrayBuffer` views API -- see [RFC 5](https://github.com/neon-bindings/rfcs/blob/main/text/0005-array-buffer-views.md) (#306)
|
||||
* VM 2.0 -- see [RFC 14](https://github.com/neon-bindings/rfcs/blob/main/text/0014-vm-2.0.md) (#306)
|
||||
* New `JsString` constructor -- see [RFC 21](https://github.com/neon-bindings/rfcs/blob/main/text/0021-string-constructor.md) (#322)
|
||||
* Eliminated `JsInteger`, `JsVariant`, `callee()` -- see [RFC 22](https://github.com/neon-bindings/rfcs/blob/main/text/0022-zero-dot-two.md) (#323)
|
||||
* Renamed `Key` to `PropertyKey` and its method names -- see [RFC 22](https://github.com/neon-bindings/rfcs/blob/main/text/0022-zero-dot-two.md) (#323)
|
||||
* Module reorganization -- see [RFC 20](https://github.com/neon-bindings/rfcs/blob/main/text/0020-module-reorg.md) (#324)
|
||||
* New `JsError` API -- see [RFC 23](https://github.com/neon-bindings/rfcs/blob/main/text/0023-error-subtyping.md) (#325)
|
||||
* Eliminated `ToJsString` API -- see [RFC 22](https://github.com/neon-bindings/rfcs/blob/main/text/0022-zero-dot-two.md) (#326)
|
||||
* Eliminated `NEON_NODE_ABI` env var -- see [RFC 22](https://github.com/neon-bindings/rfcs/blob/main/text/0022-zero-dot-two.md) (#327)
|
||||
* Default to release builds -- see [RFC 22](https://github.com/neon-bindings/rfcs/blob/main/text/0022-zero-dot-two.md) (#328)
|
||||
* Made `Buffer` construction safe by default (#329, #331)
|
||||
* Made `Throw` not implement `std::error::Error` to avoid accidental suppression, thanks to [@kjvalencik](https://github.com/kjvalencik) (#334)
|
||||
* Fixed a bug causing unnecessary rebuilds, thanks to [@kjvalencik](https://github.com/kjvalencik) (#343)
|
||||
* Fixed a soundness bug in the `Task` API, thanks to [@kjvalencik](https://github.com/kjvalencik) (#335)
|
||||
|
||||
# Version 0.1.23
|
||||
|
||||
* Optimization in `Scope` structures, thanks to [@maciejhirsz](https://github.com/maciejhirsz) (#282)
|
||||
* Fixed a memory leak in the `Task` API, thanks to [@kjvalencik](https://github.com/kjvalencik) (#291)
|
||||
* Add support for Node 10, thanks to [@mhsjlw](https://github.com/mhsjlw) and [@nomadtechie](https://github.com/nomadtechie) (#314)
|
||||
|
||||
# Version 0.1.22
|
||||
|
||||
* Reinstate `JsInteger` (although it's deprecated) for now, to be removed in 0.2. (#279)
|
||||
|
||||
# Version 0.1.21
|
||||
|
||||
* Fix a bug that was causing annoying unnecessary rebuilds ([#242](https://github.com/neon-bindings/neon/issues/242)).
|
||||
* New [API for getting the global object](https://api.neon-bindings.com/neon/scope/trait.scope#method.global) ([#249](https://github.com/neon-bindings/neon/issues/249)).
|
||||
|
||||
# Version 0.1.20
|
||||
|
||||
* Background task API ([#214](https://github.com/neon-bindings/neon/pull/214)).
|
||||
* Fixes to Windows builds ([#221](https://github.com/neon-bindings/neon/pull/221), [#227](https://github.com/neon-bindings/neon/pull/227)), thanks to [@hone](https://github.com/hone)'s tenacious troubleshooting.
|
||||
|
||||
# Version 0.1.19
|
||||
|
||||
* TypeScript upgrade fixes ([neon-bindings/neon-cli#62](https://github.com/neon-bindings/neon-cli/pull/62), [neon-bindings/neon-cli#65](https://github.com/neon-bindings/neon-cli/pull/65)).
|
||||
|
||||
# Version 0.1.18
|
||||
|
||||
* CLI bugfix ([neon-bindings/neon-cli#59](https://github.com/neon-bindings/neon-cli/pull/59)).
|
||||
* JsArrayBuffer ([#210](https://github.com/neon-bindings/neon/pull/210)).
|
||||
|
||||
# Version 0.1.17
|
||||
|
||||
* CLI bugfix ([neon-bindings/neon-cli#57](https://github.com/neon-bindings/neon-cli/pull/57)).
|
||||
|
||||
# Version 0.1.16
|
||||
|
||||
* CLI bugfix ([neon-bindings/neon-cli#56](https://github.com/neon-bindings/neon-cli/pull/56)).
|
||||
|
||||
# Version 0.1.15 (2017-05-21)
|
||||
|
||||
* Better Electron support in CLI's build process.
|
||||
* Better support for Electron via the artifacts file ([neon-bindings/neon-cli#52](https://github.com/neon-bindings/neon-cli/pull/52)).
|
||||
|
||||
# Version 0.1.14 (2017-04-02)
|
||||
|
||||
* Ensure failing tests break the build ([#191](https://github.com/neon-bindings/neon/pull/191))
|
||||
* Catch Rust panics and convert them to JS exceptions ([#192](https://github.com/neon-bindings/neon/pull/192))
|
||||
* Implement `Error` for `Throw` ([#201](https://github.com/neon-bindings/neon/pull/191))
|
||||
* Clean up the CLI and allow `neon build` to optionally take module names ([neon-bindings/neon-cli#48](https://github.com/neon-bindings/neon-cli/pull/48)).
|
||||
|
||||
# Version 0.1.13 (2017-02-17)
|
||||
|
||||
* More robust build scripts for neon-runtime, fixing Homebrew node installations (see [#189](https://github.com/neon-bindings/neon/pull/189))
|
||||
|
||||
# Version 0.1.12 (2017-02-16)
|
||||
|
||||
* [Optimized rooting protocol](https://github.com/neon-bindings/neon/commit/cef41584d9978eda2d59866a077cfe7c7d3fa46e)
|
||||
* [Eliminate rustc warnings](https://github.com/neon-bindings/neon/pull/107)
|
||||
* Lots of internal API docs
|
||||
* Windows support! :tada:
|
||||
* [Renamed `neon-sys` to `neon-runtime`](https://github.com/neon-bindings/neon/issues/169)
|
||||
* Depend on `neon-build` as a build dependency (see [neon-bindings/neon-cli#46](https://github.com/neon-bindings/neon-cli/issues/46)).
|
||||
|
||||
# Version 0.1.11 (2016-08-08)
|
||||
|
||||
* [Exposed `This` trait](https://github.com/neon-bindings/neon/issues/101) to allow user-level abstractions involving `FunctionCall`
|
||||
* Bump version to match Neon so they can be kept in sync from now on.
|
||||
* Generate a `build.rs` to make Windows work (see [neon-bindings/neon-cli#42](https://github.com/neon-bindings/neon-cli/pull/42) and [neon-bindings/neon-cli#44](https://github.com/neon-bindings/neon-cli/issues/44)).
|
||||
|
||||
# Version 0.1.10 (2016-05-11)
|
||||
|
||||
* Added `JsError` API with support for throwing [all](https://github.com/neon-bindings/neon/issues/65) [standard](https://github.com/neon-bindings/neon/issues/66) [error](https://github.com/neon-bindings/neon/issues/67) [types](https://github.com/neon-bindings/neon/issues/74)
|
||||
* [Test harness and CI integration](https://github.com/neon-bindings/neon/issues/80)!! :tada: :tada: :tada:
|
||||
* API to [call JS functions from Rust](https://github.com/neon-bindings/neon/issues/60)
|
||||
* API to [new JS functions from Rust](https://github.com/neon-bindings/neon/issues/61)
|
||||
* Added [generalized `as_slice` and `as_mut_slice` methods](https://github.com/neon-bindings/neon/issues/64) to `CSlice` API.
|
||||
* Fixed a [soundness issue](https://github.com/neon-bindings/neon/issues/64) with Locks.
|
||||
|
||||
## Incompatible Changes
|
||||
|
||||
* The `JsTypeError` type is gone, and replaced by the more general `JsError` type.
|
||||
* `neon::js::error::JsTypeError::throw(msg)` is now `neon::js::error::JsError::throw(neon::js::error::kind::TypeError, msg)`
|
||||
93
SourceCodePro-LICENSE.txt
Normal file
93
SourceCodePro-LICENSE.txt
Normal file
@ -0,0 +1,93 @@
|
||||
Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
|
||||
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
BIN
SourceCodePro-Regular.woff
Normal file
BIN
SourceCodePro-Regular.woff
Normal file
Binary file not shown.
BIN
SourceCodePro-Semibold.woff
Normal file
BIN
SourceCodePro-Semibold.woff
Normal file
Binary file not shown.
BIN
SourceSerifPro-Bold.ttf.woff
Normal file
BIN
SourceSerifPro-Bold.ttf.woff
Normal file
Binary file not shown.
BIN
SourceSerifPro-Bold.woff
Normal file
BIN
SourceSerifPro-Bold.woff
Normal file
Binary file not shown.
BIN
SourceSerifPro-It.ttf.woff
Normal file
BIN
SourceSerifPro-It.ttf.woff
Normal file
Binary file not shown.
93
SourceSerifPro-LICENSE.md
Normal file
93
SourceSerifPro-LICENSE.md
Normal file
@ -0,0 +1,93 @@
|
||||
Copyright 2014-2018 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
|
||||
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
93
SourceSerifPro-LICENSE.txt
Normal file
93
SourceSerifPro-LICENSE.txt
Normal file
@ -0,0 +1,93 @@
|
||||
Copyright 2014 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
|
||||
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
BIN
SourceSerifPro-Regular.ttf.woff
Normal file
BIN
SourceSerifPro-Regular.ttf.woff
Normal file
Binary file not shown.
BIN
SourceSerifPro-Regular.woff
Normal file
BIN
SourceSerifPro-Regular.woff
Normal file
Binary file not shown.
6
aliases.js
Normal file
6
aliases.js
Normal file
@ -0,0 +1,6 @@
|
||||
var ALIASES = {};
|
||||
ALIASES['cslice'] = {};
|
||||
ALIASES['neon'] = {};
|
||||
ALIASES['neon_runtime'] = {};
|
||||
ALIASES['semver'] = {};
|
||||
ALIASES['semver_parser'] = {};
|
||||
1
brush.svg
Normal file
1
brush.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1792" height="1792" viewBox="0 0 1792 1792"><path d="M1615 0q70 0 122.5 46.5t52.5 116.5q0 63-45 151-332 629-465 752-97 91-218 91-126 0-216.5-92.5t-90.5-219.5q0-128 92-212l638-579q59-54 130-54zm-909 1034q39 76 106.5 130t150.5 76l1 71q4 213-129.5 347t-348.5 134q-123 0-218-46.5t-152.5-127.5-86.5-183-29-220q7 5 41 30t62 44.5 59 36.5 46 17q41 0 55-37 25-66 57.5-112.5t69.5-76 88-47.5 103-25.5 125-10.5z"/></svg>
|
||||
|
After Width: | Height: | Size: 455 B |
7
build.rs
7
build.rs
@ -1,7 +0,0 @@
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
if let Ok(profile) = env::var("PROFILE") {
|
||||
println!("cargo:rustc-cfg=neon_profile={:?}", profile);
|
||||
}
|
||||
}
|
||||
3
cfg_if/all.html
Normal file
3
cfg_if/all.html
Normal file
@ -0,0 +1,3 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="List of all items in this crate"><meta name="keywords" content="rust, rustlang, rust-lang"><title>List of all items in this crate</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../cfg_if/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>−</span>]</a></span>
|
||||
</span>
|
||||
<span class='in-band'>List of all items</span></h1><h3 id='Macros'>Macros</h3><ul class='macros docblock'><li><a href='macro.cfg_if.html'>cfg_if</a></li></ul></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "cfg_if";</script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>
|
||||
22
cfg_if/index.html
Normal file
22
cfg_if/index.html
Normal file
@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `cfg_if` crate."><meta name="keywords" content="rust, rustlang, rust-lang, cfg_if"><title>cfg_if - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../cfg_if/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><p class='location'>Crate cfg_if</p><div class="sidebar-elems"><a id='all-types' href='all.html'><p>See all cfg_if's items</p></a><div class="block items"><ul><li><a href="#macros">Macros</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'cfg_if', ty: 'mod', relpath: '../'};</script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>−</span>]</a></span><a class='srclink' href='../src/cfg_if/lib.rs.html#1-176' title='goto source code'>[src]</a></span><span class='in-band'>Crate <a class="mod" href=''>cfg_if</a></span></h1><div class='docblock'><p>A macro for defining <code>#[cfg]</code> if-else statements.</p>
|
||||
<p>The macro provided by this crate, <code>cfg_if</code>, is similar to the <code>if/elif</code> C
|
||||
preprocessor macro by allowing definition of a cascade of <code>#[cfg]</code> cases,
|
||||
emitting the implementation which matches first.</p>
|
||||
<p>This allows you to conveniently provide a long list <code>#[cfg]</code>'d blocks of code
|
||||
without having to rewrite each clause multiple times.</p>
|
||||
<h1 id="example" class="section-header"><a href="#example">Example</a></h1>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="ident">cfg_if</span>::<span class="macro">cfg_if</span><span class="macro">!</span> {
|
||||
<span class="kw">if</span> <span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">unix</span>)]</span> {
|
||||
<span class="kw">fn</span> <span class="ident">foo</span>() { <span class="comment">/* unix specific functionality */</span> }
|
||||
} <span class="kw">else</span> <span class="kw">if</span> <span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">target_pointer_width</span> <span class="op">=</span> <span class="string">"32"</span>)]</span> {
|
||||
<span class="kw">fn</span> <span class="ident">foo</span>() { <span class="comment">/* non-unix, 32-bit functionality */</span> }
|
||||
} <span class="kw">else</span> {
|
||||
<span class="kw">fn</span> <span class="ident">foo</span>() { <span class="comment">/* fallback implementation */</span> }
|
||||
}
|
||||
}
|
||||
</pre></div>
|
||||
</div><h2 id='macros' class='section-header'><a href="#macros">Macros</a></h2>
|
||||
<table><tr class='module-item'><td><a class="macro" href="macro.cfg_if.html" title='cfg_if::cfg_if macro'>cfg_if</a></td><td class='docblock-short'><p>The main macro provided by this crate. See crate documentation for more
|
||||
information.</p>
|
||||
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "cfg_if";</script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>
|
||||
10
cfg_if/macro.cfg_if!.html
Normal file
10
cfg_if/macro.cfg_if!.html
Normal file
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=macro.cfg_if.html">
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="macro.cfg_if.html">macro.cfg_if.html</a>...</p>
|
||||
<script>location.replace("macro.cfg_if.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
20
cfg_if/macro.cfg_if.html
Normal file
20
cfg_if/macro.cfg_if.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `cfg_if` macro in crate `cfg_if`."><meta name="keywords" content="rust, rustlang, rust-lang, cfg_if"><title>cfg_if::cfg_if - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc macro"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../cfg_if/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='index.html'>cfg_if</a></p><script>window.sidebarCurrent = {name: 'cfg_if', ty: 'macro', relpath: ''};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>−</span>]</a></span><a class='srclink' href='../src/cfg_if/lib.rs.html#34-87' title='goto source code'>[src]</a></span><span class='in-band'>Macro <a href='index.html'>cfg_if</a>::<wbr><a class="macro" href=''>cfg_if</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><div class="example-wrap"><pre class="rust macro">
|
||||
<span class="macro">macro_rules</span><span class="macro">!</span> <span class="ident">cfg_if</span> {
|
||||
($(
|
||||
<span class="kw">if</span> <span class="attribute">#[<span class="ident">cfg</span>($(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">meta</span>:<span class="ident">meta</span>),<span class="kw-2">*</span>)]</span> { $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">tokens</span>:<span class="ident">tt</span>)<span class="op">*</span> }
|
||||
) <span class="kw">else</span> <span class="op">*</span> <span class="kw">else</span> {
|
||||
$(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">tokens2</span>:<span class="ident">tt</span>)<span class="op">*</span>
|
||||
}) <span class="op">=</span><span class="op">></span> { ... };
|
||||
(
|
||||
<span class="kw">if</span> <span class="attribute">#[<span class="ident">cfg</span>($(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">i_met</span>:<span class="ident">meta</span>),<span class="kw-2">*</span>)]</span> { $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">i_tokens</span>:<span class="ident">tt</span>)<span class="op">*</span> }
|
||||
$(
|
||||
<span class="kw">else</span> <span class="kw">if</span> <span class="attribute">#[<span class="ident">cfg</span>($(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">e_met</span>:<span class="ident">meta</span>),<span class="kw-2">*</span>)]</span> { $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">e_tokens</span>:<span class="ident">tt</span>)<span class="op">*</span> }
|
||||
)<span class="op">*</span>
|
||||
) <span class="op">=</span><span class="op">></span> { ... };
|
||||
(@<span class="ident">__items</span> ($(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">not</span>:<span class="ident">meta</span>,)<span class="kw-2">*</span>) ; ) <span class="op">=</span><span class="op">></span> { ... };
|
||||
(@<span class="ident">__items</span> ($(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">not</span>:<span class="ident">meta</span>,)<span class="kw-2">*</span>) ; ( ($(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">m</span>:<span class="ident">meta</span>),<span class="kw-2">*</span>) ($(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">tokens</span>:<span class="ident">tt</span>)<span class="kw-2">*</span>) ), $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">rest</span>:<span class="ident">tt</span>)<span class="kw-2">*</span>) <span class="op">=</span><span class="op">></span> { ... };
|
||||
(@<span class="ident">__identity</span> $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">tokens</span>:<span class="ident">tt</span>)<span class="kw-2">*</span>) <span class="op">=</span><span class="op">></span> { ... };
|
||||
}</pre></div>
|
||||
</div><div class='docblock'><p>The main macro provided by this crate. See crate documentation for more
|
||||
information.</p>
|
||||
</div></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "cfg_if";</script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>
|
||||
1
cfg_if/sidebar-items.js
Normal file
1
cfg_if/sidebar-items.js
Normal file
@ -0,0 +1 @@
|
||||
initSidebarItems({"macro":[["cfg_if","The main macro provided by this crate. See crate documentation for more information."]]});
|
||||
@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2015 David Herman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@ -1,5 +0,0 @@
|
||||
# The Neon Command-Line Tool
|
||||
|
||||
Automatically create and build [Neon](https://github.com/neon-bindings/neon) modules.
|
||||
|
||||
For more information, see the [Neon home page](https://www.neon-bindings.com)!
|
||||
@ -1,8 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('make-promises-safe');
|
||||
var CLI = require('../lib/cli.js').default;
|
||||
var cli = new CLI(process.argv, process.cwd());
|
||||
cli.exec()
|
||||
.then(function() { process.exit(0); })
|
||||
.catch(function() { process.exit(1); });
|
||||
1779
cli/package-lock.json
generated
1779
cli/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,53 +0,0 @@
|
||||
{
|
||||
"name": "neon-cli",
|
||||
"version": "0.8.2",
|
||||
"description": "Build and load native Rust/Neon modules.",
|
||||
"author": "Dave Herman <david.herman@gmail.com>",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/neon-bindings/neon.git"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"bin": {
|
||||
"neon": "bin/cli.js"
|
||||
},
|
||||
"license": "SEE LICENSE IN LICENSE-*",
|
||||
"dependencies": {
|
||||
"chalk": "^4.1.0",
|
||||
"command-line-args": "^5.1.1",
|
||||
"command-line-commands": "^3.0.1",
|
||||
"command-line-usage": "^6.1.0",
|
||||
"git-config": "0.0.7",
|
||||
"handlebars": "^4.7.6",
|
||||
"inquirer": "^7.3.3",
|
||||
"make-promises-safe": "^5.1.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"semver": "^7.3.2",
|
||||
"toml": "^3.0.0",
|
||||
"ts-typed-json": "^0.3.2",
|
||||
"validate-npm-package-license": "^3.0.4",
|
||||
"validate-npm-package-name": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chalk": "^2.2.0",
|
||||
"@types/inquirer": "^7.3.0",
|
||||
"@types/mocha": "^8.0.1",
|
||||
"@types/node": "10.17.26",
|
||||
"@types/rimraf": "^3.0.0",
|
||||
"@types/semver": "^7.3.1",
|
||||
"mocha": "^8.1.0",
|
||||
"typescript": "^3.9.7"
|
||||
},
|
||||
"scripts": {
|
||||
"transpile": "tsc",
|
||||
"prepublishOnly": "npm run transpile"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/neon-bindings/neon/issues"
|
||||
},
|
||||
"homepage": "https://www.neon-bindings.com",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
}
|
||||
@ -1,112 +0,0 @@
|
||||
import BuildSettings from './build-settings';
|
||||
import { writeFileSync } from 'fs';
|
||||
import * as JSON from 'ts-typed-json';
|
||||
|
||||
/**
|
||||
* The current state of build artifacts, for all targets.
|
||||
*/
|
||||
export default class Artifacts {
|
||||
/**
|
||||
* The relative path within the `target` directory to the current active build,
|
||||
* i.e., the build that was most recently copied as the main `.node` addon.
|
||||
*/
|
||||
private active: string | null;
|
||||
|
||||
/**
|
||||
* A table tracking the state of any build artifacts in the `target`
|
||||
* directory.
|
||||
*
|
||||
* On Windows, this table has the type:
|
||||
*
|
||||
* ```json
|
||||
* {
|
||||
* "i686-pc-windows-msvc\\debug"?: BuildSettings,
|
||||
* "i686-pc-windows-msvc\\release"?: BuildSettings,
|
||||
* "x86_64-pc-windows-msvc\\debug"?: BuildSettings,
|
||||
* "x86_64-pc-windows-msvc\\release"?: BuildSettings
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* On Linux and macOS, this table has the type:
|
||||
*
|
||||
* ```json
|
||||
* {
|
||||
* "debug"?: BuildSettings,
|
||||
* "release"?: BuildSettings
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
private targets: Record<string, BuildSettings>;
|
||||
|
||||
constructor(active: string | null = null,
|
||||
targets: Record<string, BuildSettings> = {})
|
||||
{
|
||||
this.active = active;
|
||||
this.targets = targets;
|
||||
}
|
||||
|
||||
static load(file: string) {
|
||||
try {
|
||||
return Artifacts.fromJSON(JSON.loadSync(file));
|
||||
} catch (e) {
|
||||
return new Artifacts();
|
||||
}
|
||||
}
|
||||
|
||||
static fromJSON(json: JSON.Value): Artifacts {
|
||||
json = JSON.asObject(json, "json");
|
||||
const active = json.active;
|
||||
if (typeof active !== 'string' && active !== null) {
|
||||
throw new TypeError("json.active is not a string or null");
|
||||
}
|
||||
const jsonTargets = JSON.asObject(json.targets, "json.targets");
|
||||
let targets: Record<string, BuildSettings> = {};
|
||||
for (let key of Object.keys(jsonTargets)) {
|
||||
targets[key] = BuildSettings.fromJSON(jsonTargets[key]);
|
||||
}
|
||||
return new Artifacts(active, targets);
|
||||
}
|
||||
|
||||
toJSON(): JSON.Object {
|
||||
let targets = {};
|
||||
for (let target of Object.keys(this.targets)) {
|
||||
targets[target] = this.targets[target].toJSON();
|
||||
}
|
||||
|
||||
return {
|
||||
active: this.active,
|
||||
targets: targets
|
||||
};
|
||||
}
|
||||
|
||||
save(file: string) {
|
||||
writeFileSync(file, JSON.stringify(this.toJSON()));
|
||||
}
|
||||
|
||||
lookup(path: string) {
|
||||
return this.targets[path];
|
||||
}
|
||||
|
||||
activate(path: string, settings: BuildSettings) {
|
||||
this.targets[path] = settings;
|
||||
this.active = path;
|
||||
}
|
||||
|
||||
haveActivated(path: string): boolean {
|
||||
return this.active === path;
|
||||
}
|
||||
|
||||
delete(path: string) {
|
||||
delete this.targets[path];
|
||||
|
||||
// If the path being deleted was the active one, there's no more active path.
|
||||
if (this.active === path) {
|
||||
this.active = null;
|
||||
}
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.active = null;
|
||||
this.targets = {};
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
import { promisify } from 'util';
|
||||
import child from 'child_process';
|
||||
|
||||
export function spawn(command: string, args?: string[], options?: child.SpawnOptions): Promise<number> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let ps = child.spawn(command, args || [], options!);
|
||||
ps.on('error', reject);
|
||||
ps.on('close', resolve);
|
||||
});
|
||||
}
|
||||
|
||||
export const execFile = promisify(child.execFile);
|
||||
@ -1,4 +0,0 @@
|
||||
import _rimraf from 'rimraf';
|
||||
import { promisify } from 'util';
|
||||
|
||||
export const rimraf = promisify(_rimraf);
|
||||
@ -1,98 +0,0 @@
|
||||
import * as rust from './rust';
|
||||
import * as JSON from 'ts-typed-json';
|
||||
|
||||
function isStringDict(x: JSON.Object): x is Record<string, string | null> {
|
||||
for (let key of Object.keys(x)) {
|
||||
if (x[key] !== null && typeof x[key] !== 'string') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export default class BuildSettings {
|
||||
private rustc: string;
|
||||
private nodeVersion: string | null;
|
||||
private env: Record<string, string | null>;
|
||||
|
||||
constructor(rustc: string, nodeVersion: string | null, env: Record<string, string | null>) {
|
||||
this.rustc = rustc;
|
||||
this.nodeVersion = nodeVersion;
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
match(other: BuildSettings) {
|
||||
if (other.nodeVersion !== this.nodeVersion) {
|
||||
return false;
|
||||
}
|
||||
return Object.keys(this.env).every(key => {
|
||||
return (!this.env[key] && !other.env[key]) ||
|
||||
(this.env[key] === other.env[key]);
|
||||
});
|
||||
}
|
||||
|
||||
static getNodeVersion(): string {
|
||||
return process.version;
|
||||
}
|
||||
|
||||
static current(toolchain: rust.Toolchain = 'default') {
|
||||
let rustcVersionResult = rust.spawnSync("rustc", ["--version"], toolchain);
|
||||
let nodeVersion = BuildSettings.getNodeVersion();
|
||||
|
||||
if (rustcVersionResult.error) {
|
||||
if (rustcVersionResult.error.message.includes("ENOENT")) {
|
||||
throw new Error('Rust is not installed or rustc is not in your path.');
|
||||
}
|
||||
throw rustcVersionResult.error;
|
||||
}
|
||||
|
||||
let rustc = rustcVersionResult.stdout
|
||||
.toString()
|
||||
.trim();
|
||||
|
||||
return new BuildSettings(rustc, nodeVersion, {
|
||||
npm_config_target: process.env.npm_config_target || null,
|
||||
npm_config_arch: process.env.npm_config_arch || null,
|
||||
npm_config_target_arch: process.env.npm_config_target_arch || null,
|
||||
npm_config_disturl: process.env.npm_config_disturl || null,
|
||||
npm_config_runtime: process.env.npm_config_runtime || null,
|
||||
npm_config_build_from_source: process.env.npm_config_build_from_source || null,
|
||||
npm_config_devdir: process.env.npm_config_devdir || null,
|
||||
npm_config_node_engine: process.env.npm_config_node_engine || null,
|
||||
npm_config_nodedir: process.env.npm_config_nodedir || null,
|
||||
npm_config_node_gyp: process.env.npm_config_node_gyp || null,
|
||||
npm_config_platform: process.env.npm_config_platform || null
|
||||
});
|
||||
}
|
||||
|
||||
static fromJSON(value: JSON.Value): BuildSettings {
|
||||
value = JSON.asObject(value, "value")
|
||||
let { rustc, env, nodeVersion } = value;
|
||||
if (typeof rustc !== 'string') {
|
||||
throw new TypeError("value.rustc must be a string");
|
||||
}
|
||||
if ('nodeVersion' in value) {
|
||||
if (typeof nodeVersion !== 'string' && nodeVersion !== null) {
|
||||
throw new TypeError("value.nodeVersion must be a string or null");
|
||||
}
|
||||
} else {
|
||||
nodeVersion = null;
|
||||
}
|
||||
if (!JSON.isObject(env)) {
|
||||
throw new TypeError("value.env must be an object");
|
||||
}
|
||||
if (!isStringDict(env)) {
|
||||
throw new TypeError("value.env must be a string dict");
|
||||
}
|
||||
return new BuildSettings(rustc, nodeVersion, env);
|
||||
}
|
||||
|
||||
toJSON(): JSON.Object {
|
||||
return {
|
||||
"rustc": this.rustc,
|
||||
"nodeVersion": this.nodeVersion,
|
||||
"env": this.env
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
326
cli/src/cli.ts
326
cli/src/cli.ts
@ -1,326 +0,0 @@
|
||||
import path from 'path';
|
||||
import neon_new from './ops/neon_new';
|
||||
import neon_build from './ops/neon_build';
|
||||
import neon_clean from './ops/neon_clean';
|
||||
import * as style from './style';
|
||||
import cliCommands = require('command-line-commands');
|
||||
import cliArgs = require('command-line-args');
|
||||
import cliUsage = require('command-line-usage');
|
||||
import log from './log';
|
||||
import { setup as setupLogging } from './log';
|
||||
import * as JSON from 'ts-typed-json';
|
||||
import { Toolchain } from './rust';
|
||||
|
||||
let metadata = JSON.loadSync(path.resolve(__dirname, '..', 'package.json'));
|
||||
|
||||
function commandUsage(command: string) {
|
||||
if (!spec[command]) {
|
||||
let e = new Error();
|
||||
(e as any).command = command;
|
||||
e.name = 'INVALID_COMMAND';
|
||||
throw e;
|
||||
}
|
||||
console.error(cliUsage(spec[command].usage));
|
||||
}
|
||||
|
||||
function logIf(multiple: boolean, action: string, cwd: string, module: string) {
|
||||
if (multiple) {
|
||||
log(action + " Neon package at " + (path.relative(cwd, module) || "."));
|
||||
}
|
||||
}
|
||||
|
||||
function parseArgv(argv: string[]): { cli: string[], extra: string[] } {
|
||||
let splitAt = argv.indexOf('--');
|
||||
|
||||
// No additional arguments provided
|
||||
if (splitAt < 0) {
|
||||
return {
|
||||
cli: argv,
|
||||
extra: [],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
cli: argv.slice(0, splitAt),
|
||||
extra: argv.slice(splitAt + 1)
|
||||
};
|
||||
}
|
||||
|
||||
function parseModules(cwd: string, names: string[], paths: boolean) {
|
||||
let modules = names.length
|
||||
? names.map(m => paths ? path.resolve(cwd, m)
|
||||
: path.resolve(cwd, 'node_modules', m))
|
||||
: [cwd];
|
||||
|
||||
return {
|
||||
modules,
|
||||
multiple: modules.length > 1
|
||||
};
|
||||
}
|
||||
|
||||
type Action = (this: CLI, options: Record<string, unknown>, usage: string) => void;
|
||||
|
||||
type Command = {
|
||||
args: cliArgs.OptionDefinition[],
|
||||
usage: cliUsage.Sections,
|
||||
action: Action
|
||||
};
|
||||
|
||||
type Spec = Record<string, Command>;
|
||||
|
||||
const spec: Spec = {
|
||||
|
||||
null: {
|
||||
args: [{ name: "version", alias: "v", type: Boolean },
|
||||
{ name: "help", alias: "h", type: String, defaultValue: null }],
|
||||
usage: [{
|
||||
header: "Neon",
|
||||
content: "Neon is a tool for building native Node.js modules with Rust."
|
||||
}, {
|
||||
header: "Synopsis",
|
||||
content: "$ neon [options] <command> -- [cargo options]"
|
||||
}, {
|
||||
header: "Command List",
|
||||
content: [{ name: "new", summary: "Create a new Neon project." },
|
||||
{ name: "build", summary: "(Re)build a Neon project." },
|
||||
{ name: "clean", summary: "Remove build artifacts from a Neon project." },
|
||||
{ name: "version", summary: "Display the Neon version." },
|
||||
{ name: "help", summary: "Display help information about Neon." }]
|
||||
}],
|
||||
action: function(options, usage) {
|
||||
if (options.version && options.help === undefined) {
|
||||
spec.version.action.call(this, options);
|
||||
} else if (options.help !== undefined) {
|
||||
commandUsage(options.help as string);
|
||||
} else {
|
||||
console.error(usage);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
help: {
|
||||
args: [{ name: "command", type: String, defaultOption: true },
|
||||
{ name: "help", alias: "h", type: Boolean }],
|
||||
usage: [{
|
||||
header: "neon help",
|
||||
content: "Get help about a Neon command"
|
||||
}, {
|
||||
header: "Synopsis",
|
||||
content: "$ neon help [command]"
|
||||
}],
|
||||
action: function(options) {
|
||||
if (options && options.command) {
|
||||
commandUsage(options.command as string);
|
||||
} else if (options && options.help) {
|
||||
commandUsage('help');
|
||||
} else {
|
||||
console.error(cliUsage(spec.null.usage));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
new: {
|
||||
args: [{ name: "name", type: String, defaultOption: true },
|
||||
{ name: "neon", alias: "n", type: String },
|
||||
{ name: "features", alias: "f", type: String },
|
||||
{ name: "no-default-features", type: Boolean },
|
||||
{ name: "help", alias: "h", type: Boolean }],
|
||||
usage: [{
|
||||
header: "neon new",
|
||||
content: "Create a new Neon project."
|
||||
}, {
|
||||
header: "Synopsis",
|
||||
content: "$ neon new [options] [@<scope>/]<name>"
|
||||
}, {
|
||||
header: "Options",
|
||||
optionList: [{
|
||||
name: "neon",
|
||||
alias: "n",
|
||||
type: String,
|
||||
description: "Specify a semver version of Neon or path to a local Neon repository."
|
||||
}, {
|
||||
name: "features",
|
||||
alias: "f",
|
||||
type: String,
|
||||
description: "Space-separated list of experimental Neon features to enable."
|
||||
}, {
|
||||
name: "no-default-features",
|
||||
type: Boolean,
|
||||
description: "Do not activate the `default` Neon feature."
|
||||
}]
|
||||
}],
|
||||
action: function(options) {
|
||||
if (options.help) {
|
||||
commandUsage('new');
|
||||
} else if (!options.name) {
|
||||
console.error(cliUsage(spec.new.usage));
|
||||
} else {
|
||||
return neon_new(this.cwd,
|
||||
options.name as string,
|
||||
(options.neon || null) as (string | null),
|
||||
(options.features || null) as (string | null),
|
||||
!!options['no-default-features']);
|
||||
}
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
||||
build: {
|
||||
args: [{ name: "release", alias: "r", type: Boolean },
|
||||
{ name: "path", alias: "p", type: Boolean },
|
||||
{ name: "modules", type: String, multiple: true, defaultOption: true },
|
||||
{ name: "help", alias: "h", type: Boolean }],
|
||||
usage: [{
|
||||
header: "neon build",
|
||||
content: "(Re)build a Neon project."
|
||||
}, {
|
||||
header: "Synopsis",
|
||||
content: ["$ neon build [options]",
|
||||
"$ neon build [options] {underline module} ..."]
|
||||
}, {
|
||||
header: "Options",
|
||||
optionList: [{
|
||||
name: "release",
|
||||
alias: "r",
|
||||
type: Boolean,
|
||||
description: "Release build."
|
||||
}, {
|
||||
name: "path",
|
||||
alias: "p",
|
||||
type: Boolean,
|
||||
description: "Specify modules by path instead of name."
|
||||
}]
|
||||
}],
|
||||
action: async function(options) {
|
||||
if (options.help) {
|
||||
commandUsage('build');
|
||||
return;
|
||||
}
|
||||
|
||||
let extra = options.extra as string[];
|
||||
let { modules, multiple } = parseModules(this.cwd,
|
||||
(options.modules || []) as string[],
|
||||
!!options.path);
|
||||
|
||||
for (let module of modules) {
|
||||
logIf(multiple, "building", this.cwd, module);
|
||||
|
||||
await neon_build(module, this.toolchain, !!options.release, extra);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
clean: {
|
||||
args: [{ name: "path", alias: "p", type: Boolean },
|
||||
{ name: "modules", type: String, multiple: true, defaultOption: true },
|
||||
{ name: "help", alias: "h", type: Boolean }],
|
||||
usage: [{
|
||||
header: "neon clean",
|
||||
content: "Remove build artifacts from a Neon project."
|
||||
}, {
|
||||
header: "Synopsis",
|
||||
content: ["$ neon clean [options]",
|
||||
"$ neon clean [options] {underline module} ..."]
|
||||
}, {
|
||||
header: "Options",
|
||||
optionList: [{
|
||||
name: "path",
|
||||
alias: "p",
|
||||
type: Boolean,
|
||||
description: "Specify modules by path instead of name."
|
||||
}]
|
||||
}],
|
||||
action: async function(options) {
|
||||
if (options.help) {
|
||||
commandUsage('clean');
|
||||
return;
|
||||
}
|
||||
|
||||
let { modules, multiple } = parseModules(this.cwd,
|
||||
(options.modules || []) as string[],
|
||||
!!options.path);
|
||||
|
||||
for (let module of modules) {
|
||||
logIf(multiple, "cleaning", this.cwd, module);
|
||||
|
||||
await neon_clean(module);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
version: {
|
||||
args: [{ name: "help", alias: "h", type: Boolean }],
|
||||
usage: [{
|
||||
header: "neon version",
|
||||
content: "Display the Neon version."
|
||||
}, {
|
||||
header: "Synopsis",
|
||||
content: "$ neon version"
|
||||
}],
|
||||
action: function(options) {
|
||||
if (options.help) {
|
||||
commandUsage('version');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log((JSON.asObject(metadata)).version);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export default class CLI {
|
||||
readonly toolchain: Toolchain;
|
||||
readonly argv: string[];
|
||||
readonly cwd: string;
|
||||
|
||||
constructor(argv: string[], cwd: string) {
|
||||
// Check for a toolchain argument in the style of Rust tools (e.g., `neon +nightly build`).
|
||||
if (argv.length > 2 && argv[2].trim().startsWith('+')) {
|
||||
this.toolchain = argv[2].substring(1).trim() as Toolchain;
|
||||
this.argv = argv.slice(3);
|
||||
} else {
|
||||
this.toolchain = 'default';
|
||||
this.argv = argv.slice(2);
|
||||
}
|
||||
this.cwd = cwd;
|
||||
}
|
||||
|
||||
async exec() {
|
||||
setupLogging(msg => { console.log(style.info(msg)); });
|
||||
|
||||
let parsed;
|
||||
|
||||
try {
|
||||
parsed = cliCommands([ null, 'help', 'new', 'build', 'clean', 'version' ], this.argv);
|
||||
} catch (e) {
|
||||
spec.help.action.call(this);
|
||||
|
||||
switch (e.name) {
|
||||
case 'INVALID_COMMAND':
|
||||
console.error(style.error("No manual entry for `neon " + e.command + "`"));
|
||||
break;
|
||||
|
||||
default:
|
||||
console.error(style.error(e.message));
|
||||
break;
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
let { command, argv } = parsed;
|
||||
let { cli, extra } = parseArgv(argv);
|
||||
let options = { extra, ...cliArgs(spec[command].args, { argv: cli }) };
|
||||
await spec[command].action.call(this,
|
||||
options,
|
||||
cliUsage(spec[command].usage));
|
||||
} catch (e) {
|
||||
console.error(style.error(e.message));
|
||||
console.error();
|
||||
console.error(e.stack);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,79 +0,0 @@
|
||||
import TOML from 'toml';
|
||||
import path from 'path';
|
||||
import { readFileSync, promises as fs } from 'fs';
|
||||
import Artifacts from './artifacts';
|
||||
import Project from './project';
|
||||
import { rimraf } from './async/rimraf';
|
||||
|
||||
export type CrateOptions = {
|
||||
subdirectory?: string,
|
||||
nodefile?: string
|
||||
};
|
||||
|
||||
// Represents the native crate inside a Neon project.
|
||||
export default class Crate {
|
||||
/** The Neon project containing this crate. */
|
||||
readonly project: Project;
|
||||
/** The subpath of this crate relative to the Neon project root. */
|
||||
readonly subdirectory: string;
|
||||
/** The subpath of the `.node` addon relative to this crate root. */
|
||||
readonly nodefile: string;
|
||||
/** The absolute path of this crate. */
|
||||
readonly root: string;
|
||||
/** The absolute path of the `.node` addon. */
|
||||
readonly addon: string;
|
||||
/** The crate name extracted from the manifest. */
|
||||
readonly name: string;
|
||||
/** The absolute path of the artifacts file. */
|
||||
readonly artifactsfile: string;
|
||||
/** The state of current build artifacts for each target. */
|
||||
readonly artifacts: Artifacts;
|
||||
|
||||
constructor(project: Project, options: CrateOptions = {}) {
|
||||
let { subdirectory = 'native', nodefile = 'index.node' } = options;
|
||||
this.project = project;
|
||||
this.subdirectory = subdirectory;
|
||||
this.nodefile = nodefile;
|
||||
this.root = path.resolve(project.root, subdirectory);
|
||||
this.addon = path.resolve(this.root, nodefile);
|
||||
this.name = loadLibName(path.resolve(this.root, 'Cargo.toml'))
|
||||
this.artifactsfile =
|
||||
path.resolve(this.root, 'artifacts.json');
|
||||
this.artifacts = Artifacts.load(this.artifactsfile);
|
||||
}
|
||||
|
||||
async finish(dylib: string) {
|
||||
await rimraf(this.addon);
|
||||
await fs.copyFile(dylib, this.addon);
|
||||
}
|
||||
|
||||
async removeAddon() {
|
||||
await rimraf(this.addon);
|
||||
}
|
||||
|
||||
resetArtifacts() {
|
||||
this.artifacts.reset();
|
||||
}
|
||||
|
||||
saveArtifacts() {
|
||||
this.artifacts.save(this.artifactsfile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type Metadata = {
|
||||
lib?: {
|
||||
name?: string
|
||||
}
|
||||
}
|
||||
|
||||
function loadLibName(file: string): string {
|
||||
let metadata = TOML.parse<Metadata>(readFileSync(file, 'utf8'));
|
||||
if (!metadata) throw new Error(`Failed to parse TOML file "${file}"`)
|
||||
|
||||
if (!metadata || typeof metadata !== 'object' || !metadata?.lib?.name) {
|
||||
throw new Error("Cargo.toml does not contain a [lib] section with a 'name' field");
|
||||
}
|
||||
|
||||
return metadata.lib.name;
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
export default function() {
|
||||
throw new Error("no programmatic API available yet");
|
||||
};
|
||||
70
cli/src/interfaces/command-line.d.ts
vendored
70
cli/src/interfaces/command-line.d.ts
vendored
@ -1,70 +0,0 @@
|
||||
declare module 'command-line-usage' {
|
||||
|
||||
namespace internal {
|
||||
export type Sections = Section | Section[];
|
||||
|
||||
export type Section = ContentSection | OptionListSection;
|
||||
|
||||
export type ContentSection = {
|
||||
header: string,
|
||||
content: string | string[] | Record<string, any>[],
|
||||
raw?: boolean
|
||||
};
|
||||
|
||||
export type OptionListSection = {
|
||||
header: string,
|
||||
optionList: OptionDefinition[],
|
||||
group?: string | string[],
|
||||
hide?: string | string[]
|
||||
};
|
||||
|
||||
export type OptionDefinition = {
|
||||
name: string,
|
||||
type: (value: any) => any,
|
||||
alias?: string,
|
||||
multiple?: boolean,
|
||||
defaultOption?: boolean,
|
||||
defaultValue?: any,
|
||||
group?: string | string[],
|
||||
description?: string,
|
||||
typeLabel?: string
|
||||
};
|
||||
}
|
||||
|
||||
function internal(sections: internal.Sections): string;
|
||||
|
||||
export = internal;
|
||||
}
|
||||
|
||||
declare module 'command-line-commands' {
|
||||
function internal(commands: string | null | (string | null)[], argv?: string[]): { command: string, argv: string[] };
|
||||
export = internal;
|
||||
}
|
||||
|
||||
declare module 'command-line-args' {
|
||||
|
||||
namespace internal {
|
||||
export type CommandLineArgsOptions = {
|
||||
argv?: string[],
|
||||
partial?: boolean
|
||||
};
|
||||
|
||||
export type OptionDefinition = {
|
||||
name: string,
|
||||
type: (value: any) => any,
|
||||
alias?: string,
|
||||
multiple?: boolean,
|
||||
defaultOption?: boolean,
|
||||
defaultValue?: any,
|
||||
group?: string | string[],
|
||||
description?: string,
|
||||
typeLabel?: string
|
||||
};
|
||||
}
|
||||
|
||||
function internal(optionDefinitions: internal.OptionDefinition[],
|
||||
options?: internal.CommandLineArgsOptions)
|
||||
: Record<string, unknown>;
|
||||
|
||||
export = internal;
|
||||
}
|
||||
12
cli/src/interfaces/git-config.d.ts
vendored
12
cli/src/interfaces/git-config.d.ts
vendored
@ -1,12 +0,0 @@
|
||||
declare module 'git-config' {
|
||||
export type Config = {
|
||||
user: {
|
||||
name?: string,
|
||||
email?: string
|
||||
},
|
||||
github: {
|
||||
user?: string
|
||||
}
|
||||
}
|
||||
export function sync(gitFile?: string): Config;
|
||||
}
|
||||
3
cli/src/interfaces/toml.d.ts
vendored
3
cli/src/interfaces/toml.d.ts
vendored
@ -1,3 +0,0 @@
|
||||
declare module 'toml' {
|
||||
export function parse<T extends object>(source: string): Partial<T> | undefined | null;
|
||||
}
|
||||
27
cli/src/interfaces/validate-npm-package.d.ts
vendored
27
cli/src/interfaces/validate-npm-package.d.ts
vendored
@ -1,27 +0,0 @@
|
||||
declare module 'validate-npm-package-name' {
|
||||
namespace internal {
|
||||
export type Validation = {
|
||||
validForOldPackages: boolean,
|
||||
validForNewPackages: boolean,
|
||||
warnings?: string[],
|
||||
errors?: string[]
|
||||
}
|
||||
}
|
||||
function internal(name: string): internal.Validation;
|
||||
export = internal;
|
||||
}
|
||||
|
||||
declare module 'validate-npm-package-license' {
|
||||
namespace internal {
|
||||
export type Validation = {
|
||||
validForOldPackages: boolean,
|
||||
validForNewPackages: boolean,
|
||||
warnings?: string[],
|
||||
spdx?: boolean,
|
||||
inFile?: string,
|
||||
unlicensed?: boolean
|
||||
}
|
||||
}
|
||||
function internal(license: string): internal.Validation;
|
||||
export = internal;
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
export type Logger = (msg: string) => void;
|
||||
|
||||
let logger: Logger = () => { };
|
||||
|
||||
export function setup(newLogger: Logger) {
|
||||
logger = newLogger;
|
||||
}
|
||||
|
||||
export default function log(msg: string) {
|
||||
logger(msg);
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
import Project from '../project';
|
||||
import * as rust from '../rust';
|
||||
|
||||
export default async function neon_build(root: string,
|
||||
toolchain: rust.Toolchain = 'default',
|
||||
release: boolean,
|
||||
args: string[]) {
|
||||
let project = await Project.create(root);
|
||||
await project.build(toolchain, release, args);
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
import Project from '../project';
|
||||
|
||||
export default async function neon_clean(root: string) {
|
||||
let project = await Project.create(root);
|
||||
await project.clean();
|
||||
}
|
||||
@ -1,255 +0,0 @@
|
||||
import { mkdirSync, writeFileSync, promises as fsPromises } from 'fs';
|
||||
import { prompt } from 'inquirer';
|
||||
import path from 'path';
|
||||
import handlebars from 'handlebars';
|
||||
import semver from 'semver';
|
||||
import * as style from '../style';
|
||||
import validateLicense = require('validate-npm-package-license');
|
||||
import validateName = require('validate-npm-package-name');
|
||||
import * as JSON from 'ts-typed-json';
|
||||
import gitconfig from 'git-config';
|
||||
|
||||
const { readFile, stat } = fsPromises;
|
||||
|
||||
const ROOT_DIR = path.resolve(__dirname, '..', '..');
|
||||
const TEMPLATES_DIR = path.resolve(ROOT_DIR, 'templates');
|
||||
|
||||
const NEON_CLI_VERSION =
|
||||
JSON.asString(JSON.asObject(JSON.loadSync(path.resolve(ROOT_DIR, 'package.json'))).version);
|
||||
|
||||
async function compile(filename: string) {
|
||||
let source = await readFile(path.resolve(TEMPLATES_DIR, filename), {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
return handlebars.compile(source, { noEscape: true });
|
||||
}
|
||||
|
||||
const GITIGNORE_TEMPLATE = compile('.gitignore.hbs');
|
||||
const CARGO_TEMPLATE = compile('Cargo.toml.hbs');
|
||||
const NPM_TEMPLATE = compile('package.json.hbs');
|
||||
const INDEXJS_TEMPLATE = compile('index.js.hbs');
|
||||
const LIBRS_TEMPLATE = compile('lib.rs.hbs');
|
||||
const README_TEMPLATE = compile('README.md.hbs');
|
||||
const BUILDRS_TEMPLATE = compile('build.rs.hbs');
|
||||
|
||||
type Author = {
|
||||
name?: string,
|
||||
email?: string
|
||||
};
|
||||
|
||||
async function guessAuthor() {
|
||||
let author: Author = {
|
||||
name: process.env.USER || process.env.USERNAME,
|
||||
email: undefined
|
||||
};
|
||||
try {
|
||||
let config = gitconfig.sync();
|
||||
if (config.user.name) {
|
||||
author.name = config.user.name;
|
||||
}
|
||||
if (config.user.email) {
|
||||
author.email = config.user.email;
|
||||
}
|
||||
return author;
|
||||
} catch (e) {
|
||||
return author;
|
||||
}
|
||||
}
|
||||
|
||||
type NeonVersion = { type: "version" | "range" | "relative" | "absolute", value: string };
|
||||
|
||||
async function parseNeonVersion(flag: string | null) : Promise<NeonVersion> {
|
||||
if (!flag) {
|
||||
return { type: "version", value: NEON_CLI_VERSION };
|
||||
}
|
||||
|
||||
if (semver.valid(flag)) {
|
||||
return { type: "version", value: flag };
|
||||
}
|
||||
|
||||
if (semver.validRange(flag)) {
|
||||
return { type: "range", value: flag };
|
||||
}
|
||||
|
||||
let stats = await stat(flag);
|
||||
|
||||
if (!stats.isDirectory()) {
|
||||
throw new Error("Specified path to Neon is not a directory");
|
||||
}
|
||||
|
||||
return { type: path.isAbsolute(flag) ? "absolute" : "relative", value: flag };
|
||||
}
|
||||
|
||||
interface Answers {
|
||||
name: {
|
||||
npm: {
|
||||
full: string;
|
||||
scope: string | null;
|
||||
local: string;
|
||||
};
|
||||
cargo: {
|
||||
external: string;
|
||||
internal: string;
|
||||
};
|
||||
};
|
||||
description: string;
|
||||
git: string;
|
||||
author: string;
|
||||
node: string;
|
||||
}
|
||||
|
||||
export default async function wizard(pwd: string, name: string, neon: string | null, features: string | null, noDefaultFeatures: boolean) {
|
||||
let warning = "WARN: `neon new` is deprecated. To create a new project use `npm init neon my-project`.";
|
||||
let banner = "".padStart(warning.length + 4, "#");
|
||||
|
||||
console.warn(`${banner}\n# ${warning} #\n${banner}\n`);
|
||||
|
||||
let its = validateName(name);
|
||||
if (!its.validForNewPackages) {
|
||||
let errors = (its.errors || []).concat(its.warnings || []);
|
||||
throw new Error("Sorry, " + errors.join(" and ") + ".");
|
||||
}
|
||||
|
||||
// check for a scoped name
|
||||
let scoped = name.match(/@([^\/]+)\/(.*)/);
|
||||
let [, scope, local] = scoped ? (scoped as [string, string, string]) : [, null, name];
|
||||
|
||||
console.log("This utility will walk you through creating the " + style.project(name) + " Neon project.");
|
||||
console.log("It only covers the most common items, and tries to guess sensible defaults.");
|
||||
console.log();
|
||||
console.log("Press ^C at any time to quit.");
|
||||
|
||||
let root = path.resolve(pwd, local);
|
||||
let guess = await guessAuthor();
|
||||
|
||||
let answers: Answers = await prompt([
|
||||
{
|
||||
type: 'input',
|
||||
name: 'version',
|
||||
message: "version",
|
||||
default: "0.1.0",
|
||||
validate: function (input) {
|
||||
if (semver.valid(input)) {
|
||||
return true;
|
||||
}
|
||||
return "Invalid version: " + input;
|
||||
}
|
||||
},
|
||||
{ type: 'input', name: 'description', message: "description" },
|
||||
{ type: 'input', name: 'node', message: "node entry point", default: "lib/index.js" },
|
||||
{ type: 'input', name: 'git', message: "git repository" },
|
||||
{ type: 'input', name: 'author', message: "author", default: guess.name },
|
||||
{ type: 'input', name: 'email', message: "email", default: guess.email },
|
||||
{
|
||||
type: 'input',
|
||||
name: 'license',
|
||||
message: "license",
|
||||
default: "MIT",
|
||||
validate: function (input) {
|
||||
let its = validateLicense(input);
|
||||
if (its.validForNewPackages) {
|
||||
return true;
|
||||
}
|
||||
let errors = its.warnings || [];
|
||||
return "Sorry, " + errors.join(" and ") + ".";
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
answers.name = {
|
||||
npm: {
|
||||
full: name,
|
||||
scope: scope,
|
||||
local: local
|
||||
},
|
||||
cargo: {
|
||||
external: local,
|
||||
internal: local.replace(/-/g, "_")
|
||||
}
|
||||
};
|
||||
answers.description = escapeQuotes(answers.description);
|
||||
answers.git = encodeURI(answers.git);
|
||||
answers.author = escapeQuotes(answers.author);
|
||||
|
||||
let neonVersion = await parseNeonVersion(neon);
|
||||
|
||||
let simple = (neonVersion.type === 'version' || neonVersion.type === 'range')
|
||||
&& !features
|
||||
&& !noDefaultFeatures;
|
||||
|
||||
let libs: {
|
||||
// In the common case, we can make the Cargo.toml manifest simple by just using
|
||||
// the semver specifier string for the `neon` and `neon-build` dependencies.
|
||||
simple: boolean,
|
||||
paths?: { neon: string, 'neon-build': string },
|
||||
version?: string,
|
||||
features?: Array<string>,
|
||||
noDefaultFeatures: boolean
|
||||
} = { simple, noDefaultFeatures };
|
||||
|
||||
if (neonVersion.type === 'relative') {
|
||||
let neon = path.relative(path.join(name, 'native'), neonVersion.value);
|
||||
libs.paths = {
|
||||
neon: JSON.stringify(neon),
|
||||
'neon-build': JSON.stringify(path.join(neon, 'crates', 'neon-build'))
|
||||
};
|
||||
} else if (neonVersion.type === 'absolute') {
|
||||
libs.paths = {
|
||||
neon: JSON.stringify(neonVersion.value),
|
||||
'neon-build': JSON.stringify(path.resolve(neonVersion.value, 'crates', 'neon-build'))
|
||||
};
|
||||
} else {
|
||||
libs.version = JSON.stringify(neonVersion.value);
|
||||
}
|
||||
|
||||
if (features) {
|
||||
libs.features = features.split(/\s+/).map(JSON.stringify);
|
||||
}
|
||||
|
||||
let cli = JSON.stringify(neonVersion.type === 'version'
|
||||
? "^" + neonVersion.value
|
||||
: neonVersion.type === 'relative'
|
||||
? "file:" + path.join(path.relative(name, neonVersion.value), 'cli')
|
||||
: neonVersion.type === 'absolute'
|
||||
? "file:" + path.resolve(neonVersion.value, 'cli')
|
||||
: neonVersion.value);
|
||||
|
||||
let ctx = {
|
||||
project: answers,
|
||||
neon: { cli, libs }
|
||||
};
|
||||
|
||||
let lib = path.resolve(root, path.dirname(answers.node));
|
||||
let native_ = path.resolve(root, 'native');
|
||||
let src = path.resolve(native_, 'src');
|
||||
|
||||
mkdirSync(lib, { recursive: true });
|
||||
mkdirSync(src, { recursive: true });
|
||||
|
||||
writeFileSync(path.resolve(root, '.gitignore'), (await GITIGNORE_TEMPLATE)(ctx), { flag: 'wx' });
|
||||
writeFileSync(path.resolve(root, 'package.json'), (await NPM_TEMPLATE)(ctx), { flag: 'wx' });
|
||||
writeFileSync(path.resolve(native_, 'Cargo.toml'), (await CARGO_TEMPLATE)(ctx), { flag: 'wx' });
|
||||
writeFileSync(path.resolve(root, 'README.md'), (await README_TEMPLATE)(ctx), { flag: 'wx' });
|
||||
writeFileSync(path.resolve(root, answers.node), (await INDEXJS_TEMPLATE)(ctx), { flag: 'wx' });
|
||||
writeFileSync(path.resolve(src, 'lib.rs'), (await LIBRS_TEMPLATE)(ctx), { flag: 'wx' });
|
||||
writeFileSync(path.resolve(native_, 'build.rs'), (await BUILDRS_TEMPLATE)(ctx), { flag: 'wx' });
|
||||
|
||||
let relativeRoot = path.relative(pwd, root);
|
||||
let relativeNode = path.relative(pwd, path.resolve(root, answers.node));
|
||||
let relativeRust = path.relative(pwd, path.resolve(src, 'lib.rs'));
|
||||
|
||||
console.log();
|
||||
console.log("Woo-hoo! Your Neon project has been created in: " + style.path(relativeRoot));
|
||||
console.log();
|
||||
console.log("The main Node entry point is at: " + style.path(relativeNode));
|
||||
console.log("The main Rust entry point is at: " + style.path(relativeRust));
|
||||
console.log();
|
||||
console.log("To build your project, just run " + style.command("npm install") + " from within the " + style.path(relativeRoot) + " directory.");
|
||||
console.log("Then you can test it out with " + style.command("node -e 'require(\"./\")'") + ".");
|
||||
console.log();
|
||||
console.log("Happy hacking!");
|
||||
};
|
||||
|
||||
function escapeQuotes(str: string): string {
|
||||
return str.replace(/"/g, '\\"');
|
||||
}
|
||||
@ -1,74 +0,0 @@
|
||||
import path from 'path';
|
||||
import Crate from './crate';
|
||||
import Target from './target';
|
||||
import BuildSettings from './build-settings';
|
||||
import log from './log';
|
||||
import { execFile, spawn } from './async/child_process';
|
||||
import * as rust from './rust';
|
||||
|
||||
export type ProjectOptions = {
|
||||
crate: string
|
||||
targetDirectory: string
|
||||
};
|
||||
|
||||
/** A Neon project and its directory tree. */
|
||||
export default class Project {
|
||||
readonly root: string;
|
||||
readonly targetDirectory: string;
|
||||
readonly crate: Crate;
|
||||
|
||||
private constructor(root: string, options: ProjectOptions) {
|
||||
let { crate, targetDirectory } = options;
|
||||
this.root = root;
|
||||
this.targetDirectory = targetDirectory;
|
||||
this.crate = new Crate(this, { subdirectory: crate });
|
||||
}
|
||||
|
||||
static async create(root: string, options: Partial<ProjectOptions> = {}): Promise<Project> {
|
||||
let { crate = 'native' } = options;
|
||||
const { stdout } = await execFile("cargo", ["metadata", "--format-version=1", "--no-deps"], {
|
||||
cwd: path.join(root, crate)
|
||||
});
|
||||
const targetDirectory: string = JSON.parse(stdout).target_directory;
|
||||
|
||||
return new Project(root, {
|
||||
targetDirectory,
|
||||
crate,
|
||||
...options
|
||||
});
|
||||
}
|
||||
|
||||
async build(toolchain: rust.Toolchain, release: boolean, args: string[]) {
|
||||
let target = new Target(this.crate, { release: release });
|
||||
let settings = BuildSettings.current(toolchain);
|
||||
|
||||
// 1. Force a rebuild if build settings have changed.
|
||||
if (!target.inState(settings)) {
|
||||
log("forcing rebuild for new build settings");
|
||||
await target.clean();
|
||||
}
|
||||
|
||||
// 2. Build the dylib.
|
||||
log("running cargo");
|
||||
await target.build(toolchain, settings, args);
|
||||
|
||||
// 3. Copy the dylib as the main addon file.
|
||||
log("generating " + path.join(this.crate.subdirectory, this.crate.nodefile));
|
||||
await this.crate.finish(target.dylib);
|
||||
}
|
||||
|
||||
async clean() {
|
||||
// 1. Do a `cargo clean` to delete the `target` directory.
|
||||
log("cargo clean");
|
||||
await spawn("cargo", ["clean"], { cwd: this.crate.root, stdio: 'inherit' });
|
||||
|
||||
// 2. Remove the main addon file.
|
||||
log("remove " + path.join(this.crate.subdirectory, this.crate.nodefile));
|
||||
await this.crate.removeAddon();
|
||||
|
||||
// 3. Clear the artifacts file.
|
||||
this.crate.resetArtifacts();
|
||||
this.crate.saveArtifacts();
|
||||
}
|
||||
|
||||
};
|
||||
@ -1,24 +0,0 @@
|
||||
import * as async from './async/child_process';
|
||||
import * as childProcess from 'child_process';
|
||||
|
||||
export type Toolchain = 'default' | 'stable' | 'nightly' | 'beta';
|
||||
|
||||
function toolchainPrefix(toolchain: Toolchain = 'default') {
|
||||
return toolchain === 'default' ? [] : ["+" + toolchain];
|
||||
}
|
||||
|
||||
export function spawnSync(tool: string,
|
||||
args: string[],
|
||||
toolchain: Toolchain = 'default',
|
||||
options?: childProcess.SpawnOptions)
|
||||
{
|
||||
return childProcess.spawnSync(tool, toolchainPrefix(toolchain).concat(args), options);
|
||||
}
|
||||
|
||||
export function spawn(tool: string,
|
||||
args: string[],
|
||||
toolchain: Toolchain = 'default',
|
||||
options?: childProcess.SpawnOptions)
|
||||
{
|
||||
return async.spawn(tool, toolchainPrefix(toolchain).concat(args), options);
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
import chalk from 'chalk';
|
||||
|
||||
export let project = chalk.cyan.bold;
|
||||
export let command = chalk.green.bold;
|
||||
export let path = chalk.cyan;
|
||||
|
||||
export function error(msg: string): string {
|
||||
return chalk.bgBlack.cyan("neon") + " " +
|
||||
chalk.bgBlack.red("ERR!") + " " +
|
||||
msg;
|
||||
}
|
||||
|
||||
export function info(msg: string): string {
|
||||
return chalk.bgBlack.cyan("neon") + " " +
|
||||
chalk.bgBlack.gray("info") + " " +
|
||||
chalk.gray(msg);
|
||||
}
|
||||
@ -1,109 +0,0 @@
|
||||
import * as rust from './rust';
|
||||
import path from 'path';
|
||||
import Crate from './crate';
|
||||
import BuildSettings from './build-settings';
|
||||
import { rimraf } from './async/rimraf';
|
||||
|
||||
const LIB_PREFIX: Record<string, string> = {
|
||||
'darwin': "lib",
|
||||
'freebsd': "lib",
|
||||
'linux': "lib",
|
||||
'sunos': "lib",
|
||||
'win32': ""
|
||||
};
|
||||
|
||||
const LIB_SUFFIX: Record<string, string> = {
|
||||
'darwin': ".dylib",
|
||||
'freebsd': ".so",
|
||||
'linux': ".so",
|
||||
'sunos': ".so",
|
||||
'win32': ".dll"
|
||||
};
|
||||
|
||||
export type TargetOptions = {
|
||||
release?: boolean,
|
||||
arch?: string
|
||||
};
|
||||
|
||||
/** The Rust build artifacts for a single build target of a Neon crate. */
|
||||
export default class Target {
|
||||
readonly crate: Crate;
|
||||
readonly release: boolean;
|
||||
readonly arch: string;
|
||||
readonly triple: string;
|
||||
readonly subdirectory: string;
|
||||
readonly root: string;
|
||||
readonly dylib: string;
|
||||
|
||||
constructor(crate: Crate, options: TargetOptions = {}) {
|
||||
let { release = true, arch = process.env.npm_config_arch || process.arch } = options;
|
||||
this.crate = crate;
|
||||
this.release = release;
|
||||
this.arch = arch;
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
this.triple = (arch === 'ia32') ? 'i686-pc-windows-msvc' : 'x86_64-pc-windows-msvc';
|
||||
} else {
|
||||
this.triple = '';
|
||||
}
|
||||
|
||||
if (process.env.CARGO_BUILD_TARGET) {
|
||||
this.triple = process.env.CARGO_BUILD_TARGET;
|
||||
}
|
||||
|
||||
this.subdirectory = path.join(this.triple, release ? 'release' : 'debug');
|
||||
this.root = path.resolve(crate.project.targetDirectory, this.subdirectory);
|
||||
|
||||
let prefix = LIB_PREFIX[process.platform];
|
||||
let suffix = LIB_SUFFIX[process.platform];
|
||||
this.dylib = path.resolve(this.root, prefix + crate.name + suffix);
|
||||
}
|
||||
|
||||
async clean() {
|
||||
// Remove the directory associated with this target.
|
||||
const absolutePathSubdir = path.resolve(this.crate.root, 'target', this.subdirectory);
|
||||
await rimraf(absolutePathSubdir);
|
||||
|
||||
// If this target was the active target, remove the addon.
|
||||
if (this.crate.artifacts.haveActivated(this.subdirectory)) {
|
||||
await this.crate.removeAddon();
|
||||
}
|
||||
|
||||
// Update the build state.
|
||||
this.crate.artifacts.delete(this.subdirectory);
|
||||
this.crate.saveArtifacts();
|
||||
}
|
||||
|
||||
async build(toolchain: rust.Toolchain,
|
||||
settings: BuildSettings,
|
||||
additionalArgs: string[])
|
||||
{
|
||||
let releaseFlags = this.release ? ["--release"] : [];
|
||||
let targetFlags = this.triple ? ["--target=" + this.triple] : [];
|
||||
|
||||
let args = ['build'].concat(releaseFlags, targetFlags, additionalArgs);
|
||||
|
||||
try {
|
||||
let result = await rust.spawn("cargo", args, toolchain, {
|
||||
cwd: this.crate.root,
|
||||
stdio: 'inherit'
|
||||
});
|
||||
|
||||
if (result !== 0) {
|
||||
throw new Error("cargo build failed");
|
||||
}
|
||||
|
||||
this.crate.artifacts.activate(this.subdirectory, settings);
|
||||
|
||||
return result;
|
||||
} finally {
|
||||
this.crate.saveArtifacts();
|
||||
}
|
||||
}
|
||||
|
||||
inState(settings: BuildSettings) {
|
||||
let savedSettings = this.crate.artifacts.lookup(this.subdirectory);
|
||||
return savedSettings && savedSettings.match(settings);
|
||||
}
|
||||
|
||||
};
|
||||
@ -1,6 +0,0 @@
|
||||
native/target
|
||||
native/index.node
|
||||
native/artifacts.json
|
||||
**/*~
|
||||
**/node_modules
|
||||
**/.DS_Store
|
||||
@ -1,41 +0,0 @@
|
||||
[package]
|
||||
name = "{{project.name.cargo.external}}"
|
||||
version = "{{project.version}}"
|
||||
{{#if project.author}}
|
||||
authors = ["{{project.author}}{{#if project.email}} <{{project.email}}>{{/if}}"]
|
||||
{{/if}}
|
||||
{{#if project.license}}
|
||||
license = "{{project.license}}"
|
||||
{{/if}}
|
||||
build = "build.rs"
|
||||
edition = "2018"
|
||||
exclude = ["artifacts.json", "index.node"]
|
||||
|
||||
[lib]
|
||||
name = "{{project.name.cargo.internal}}"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[build-dependencies]
|
||||
{{#if neon.libs.paths}}
|
||||
neon-build = { path = {{neon.libs.paths.neon-build}} }
|
||||
{{else}}
|
||||
neon-build = {{neon.libs.version}}
|
||||
{{/if}}
|
||||
|
||||
{{#if neon.libs.simple}}
|
||||
[dependencies]
|
||||
neon = {{neon.libs.version}}
|
||||
{{else}}
|
||||
[dependencies.neon]
|
||||
{{#if neon.libs.version}}
|
||||
version = {{neon.libs.version}}
|
||||
{{else}}
|
||||
path = {{neon.libs.paths.neon}}
|
||||
{{/if}}
|
||||
{{#if neon.libs.noDefaultFeatures}}
|
||||
default-features = false
|
||||
{{/if}}
|
||||
{{#if neon.libs.features}}
|
||||
features = [{{#each neon.libs.features as |feature index|}}{{#if index}}, {{/if}}{{feature}}{{/each}}]
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
@ -1,3 +0,0 @@
|
||||
# {{project.name.npm.full}}
|
||||
|
||||
{{project.description}}
|
||||
@ -1,7 +0,0 @@
|
||||
extern crate neon_build;
|
||||
|
||||
fn main() {
|
||||
neon_build::setup(); // must be called in build.rs
|
||||
|
||||
// add project-specific build logic here...
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
var addon = require('../native');
|
||||
|
||||
console.log(addon.hello());
|
||||
@ -1,9 +0,0 @@
|
||||
use neon::prelude::*;
|
||||
|
||||
fn hello(mut cx: FunctionContext) -> JsResult<JsString> {
|
||||
Ok(cx.string("hello node"))
|
||||
}
|
||||
|
||||
register_module!(mut cx, {
|
||||
cx.export_function("hello", hello)
|
||||
});
|
||||
@ -1,24 +0,0 @@
|
||||
{
|
||||
"name": "{{project.name.npm.full}}",
|
||||
"version": "{{project.version}}",
|
||||
"description": "{{project.description}}",
|
||||
"main": "{{project.node}}",
|
||||
{{#if project.git}}
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "{{project.git}}"
|
||||
},
|
||||
{{/if}}
|
||||
{{#if project.author}}
|
||||
"author": "{{project.author}}{{#if project.email}} <{{project.email}}>{{/if}}",
|
||||
{{/if}}
|
||||
{{#if project.license}}
|
||||
"license": "{{project.license}}",
|
||||
{{/if}}
|
||||
"dependencies": {
|
||||
"neon-cli": {{neon.cli}}
|
||||
},
|
||||
"scripts": {
|
||||
"install": "neon build"
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"lib": [
|
||||
"es6",
|
||||
"es7"
|
||||
],
|
||||
"allowJs": false,
|
||||
|
||||
"sourceMap": false,
|
||||
"outDir": "lib",
|
||||
|
||||
"declaration": true,
|
||||
|
||||
"esModuleInterop": true,
|
||||
"noImplicitAny": true,
|
||||
"suppressImplicitAnyIndexErrors": true,
|
||||
"strictNullChecks": true,
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitThis": true,
|
||||
"allowUnreachableCode": false,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
[package]
|
||||
name = "neon-build"
|
||||
version = "0.8.2"
|
||||
authors = ["Dave Herman <david.herman@gmail.com>"]
|
||||
description = "Build logic required for Neon projects."
|
||||
repository = "https://github.com/neon-bindings/neon"
|
||||
license = "MIT/Apache-2.0"
|
||||
edition = "2018"
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
neon-sys = { version = "=0.8.2", path = "../neon-sys", optional = true }
|
||||
@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2015 David Herman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@ -1,22 +0,0 @@
|
||||
#[cfg(all(windows, feature = "neon-sys"))]
|
||||
fn main() {
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
// Extract linker metadata from neon-sys and save it in a text file.
|
||||
// The neon-build lib.rs will textually include them into constants.
|
||||
fn save(var: &str, filename: &str) {
|
||||
let path = Path::new(&env::var("OUT_DIR").unwrap()).join(filename);
|
||||
let mut buffer = File::create(path).unwrap();
|
||||
write!(buffer, "{}", env::var(var).unwrap()).unwrap();
|
||||
}
|
||||
|
||||
save("DEP_NEON_NODE_ROOT_DIR", "node_root_dir");
|
||||
save("DEP_NEON_NODE_ARCH", "node_arch");
|
||||
save("DEP_NEON_NODE_LIB_FILE", "node_lib_file");
|
||||
}
|
||||
|
||||
#[cfg(any(not(windows), not(feature = "neon-sys")))]
|
||||
fn main() {}
|
||||
@ -1 +0,0 @@
|
||||
pub(crate) fn setup() {}
|
||||
@ -1,4 +0,0 @@
|
||||
pub(crate) fn setup() {
|
||||
println!("cargo:rustc-cdylib-link-arg=-undefined");
|
||||
println!("cargo:rustc-cdylib-link-arg=dynamic_lookup");
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
#[cfg(all(not(windows), not(target_os = "macos")))]
|
||||
mod linux;
|
||||
#[cfg(all(not(windows), not(target_os = "macos")))]
|
||||
pub(crate) use linux::*;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
mod macos;
|
||||
#[cfg(target_os = "macos")]
|
||||
pub(crate) use macos::*;
|
||||
|
||||
#[cfg(windows)]
|
||||
mod windows;
|
||||
#[cfg(windows)]
|
||||
pub(crate) use windows::*;
|
||||
@ -1,36 +0,0 @@
|
||||
use std::env::var;
|
||||
use std::path::Path;
|
||||
|
||||
const NODE_ROOT_DIR: &'static str = include_str!(concat!(env!("OUT_DIR"), "\\node_root_dir"));
|
||||
const NODE_ARCH: &'static str = include_str!(concat!(env!("OUT_DIR"), "\\node_arch"));
|
||||
const NODE_LIB_FILE: &'static str = include_str!(concat!(env!("OUT_DIR"), "\\node_lib_file"));
|
||||
|
||||
/// Set up the build environment by setting Cargo configuration variables.
|
||||
pub(crate) fn setup() {
|
||||
let debug = var("DEBUG").ok().map_or(false, |s| s == "true");
|
||||
let configuration = if debug { "Debug" } else { "Release" };
|
||||
let node_lib_file_path = Path::new(NODE_LIB_FILE);
|
||||
let mut node_lib_path = Path::new(NODE_ROOT_DIR).to_path_buf();
|
||||
node_lib_path.push(NODE_ARCH);
|
||||
println!(
|
||||
"cargo:rustc-link-search={}\\{}",
|
||||
NODE_ROOT_DIR, configuration
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-link-search=native={}",
|
||||
&node_lib_path.display()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-link-lib={}",
|
||||
&node_lib_file_path.file_stem().unwrap().to_str().unwrap()
|
||||
);
|
||||
|
||||
// Link `win_delay_load_hook.obj` for windows electron
|
||||
let node_runtime_env = "npm_config_runtime";
|
||||
println!("cargo:rerun-if-env-changed={}", node_runtime_env);
|
||||
if var(node_runtime_env).map(|s| s == "electron") == Ok(true) {
|
||||
println!("cargo:rustc-cdylib-link-arg=win_delay_load_hook.obj");
|
||||
println!("cargo:rustc-cdylib-link-arg=delayimp.lib");
|
||||
println!("cargo:rustc-cdylib-link-arg=/DELAYLOAD:node.exe");
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
#[cfg(feature = "neon-sys")]
|
||||
mod legacy;
|
||||
#[cfg(not(feature = "neon-sys"))]
|
||||
mod napi;
|
||||
|
||||
#[cfg(not(feature = "neon-sys"))]
|
||||
pub use napi::Setup;
|
||||
|
||||
/// Custom build scripts for [Neon][neon] modules.
|
||||
/// Must be called from `main.rs` in a Cargo [build script][build-script].
|
||||
///
|
||||
/// ```toml
|
||||
/// [package]
|
||||
/// build = "build.rs"
|
||||
/// ```
|
||||
///
|
||||
/// ```rust
|
||||
/// // build.rs
|
||||
/// # #[allow(clippy::needless_doctest_main)]
|
||||
/// fn main() {
|
||||
/// neon_build::setup();
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// [neon]: https://docs.rs/neon
|
||||
/// [build-script]: https://doc.rust-lang.org/cargo/reference/build-scripts.html
|
||||
pub fn setup() {
|
||||
#[cfg(feature = "neon-sys")]
|
||||
legacy::setup();
|
||||
#[cfg(not(feature = "neon-sys"))]
|
||||
napi::setup();
|
||||
}
|
||||
@ -1,171 +0,0 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
fn manifest_dir() -> PathBuf {
|
||||
std::env::var_os("CARGO_MANIFEST_DIR")
|
||||
.map(PathBuf::from)
|
||||
.expect("Expected CARGO_MANIFEST_DIR environment variable")
|
||||
}
|
||||
|
||||
fn out_dir() -> PathBuf {
|
||||
std::env::var_os("OUT_DIR")
|
||||
.map(PathBuf::from)
|
||||
.expect("Expected OUT_DIR environment variable")
|
||||
}
|
||||
|
||||
fn is_env(env_var: &str, value: &str) -> bool {
|
||||
std::env::var_os(env_var)
|
||||
.map(|v| v == value)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn setup_unix(output_file: PathBuf) {
|
||||
println!("cargo:rustc-cdylib-link-arg=-o");
|
||||
println!("cargo:rustc-cdylib-link-arg={}", output_file.display());
|
||||
}
|
||||
|
||||
fn setup_windows(output_file: PathBuf) {
|
||||
let pdb_file = output_file
|
||||
.file_name()
|
||||
.map(|file| out_dir().join(Path::new(file).with_extension("pdb")))
|
||||
.expect("Expected a neon output file name");
|
||||
|
||||
println!("cargo:rustc-cdylib-link-arg=/OUT:{}", output_file.display());
|
||||
println!("cargo:rustc-cdylib-link-arg=/PDB:{}", pdb_file.display());
|
||||
}
|
||||
|
||||
/// `Setup` acts as a builder for initializing a Neon build script
|
||||
///
|
||||
/// A default setup builder is provided as [`neon_build::setup()`](crate::setup()).
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// Output the neon module at `lib/native.node`
|
||||
///
|
||||
/// ```
|
||||
/// # #[allow(clippy::needless_doctest_main)]
|
||||
/// fn main() {
|
||||
/// neon_build::Setup::options()
|
||||
/// .output_dir("lib")
|
||||
/// .output_dir("native.node")
|
||||
/// .setup();
|
||||
/// }
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Setup {
|
||||
output_dir: Option<PathBuf>,
|
||||
output_file: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Setup {
|
||||
/// Create a new builder for Setup options
|
||||
pub fn options() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
/// Sets the output directory for the native library.
|
||||
/// Defaults to the cargo manifest directory. If not absolute, paths will
|
||||
/// be relative to the cargo manifest directory.
|
||||
pub fn output_dir(&mut self, output_dir: impl AsRef<Path>) -> &mut Self {
|
||||
self.output_dir = Some(output_dir.as_ref().to_path_buf());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the name of the native library. Defaults to `index.node`. If not
|
||||
/// absolute, paths will be relative to the [`Setup::output_dir`].
|
||||
///
|
||||
/// **Note**: Node.js requires that native libraries have the `.node`
|
||||
/// extension to be loaded by `require`.
|
||||
pub fn output_file(&mut self, output_file: impl AsRef<Path>) -> &mut Self {
|
||||
self.output_file = Some(output_file.as_ref().to_path_buf());
|
||||
self
|
||||
}
|
||||
|
||||
/// Setup the Cargo build process for Neon. Should be called once from
|
||||
/// `fn main` in a cargo build script.
|
||||
pub fn setup(&self) {
|
||||
let output_file = self.absolute_output_file();
|
||||
let is_windows = is_env("CARGO_CFG_TARGET_OS", "windows");
|
||||
let is_gnu = is_env("CARGO_CFG_TARGET_ENV", "gnu");
|
||||
|
||||
if is_windows && !is_gnu {
|
||||
setup_windows(output_file);
|
||||
} else {
|
||||
setup_unix(output_file);
|
||||
}
|
||||
}
|
||||
|
||||
fn absolute_output_file(&self) -> PathBuf {
|
||||
let output_file = self
|
||||
.output_file
|
||||
.clone()
|
||||
.unwrap_or_else(|| PathBuf::from("index.node"));
|
||||
|
||||
// Don't prepend `output_dir` if `output_file` is absolute
|
||||
if output_file.is_absolute() {
|
||||
return output_file;
|
||||
}
|
||||
|
||||
let output_dir = if let Some(output_dir) = self.output_dir.clone() {
|
||||
// If `output_dir` is absolute, use it, otherwise
|
||||
// append it to `manifest_dir()`
|
||||
if output_dir.is_absolute() {
|
||||
output_dir
|
||||
} else {
|
||||
manifest_dir().join(output_dir)
|
||||
}
|
||||
} else {
|
||||
// Default to `manifest_dir()`
|
||||
manifest_dir()
|
||||
};
|
||||
|
||||
output_dir.join(output_file)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn setup() {
|
||||
Setup::options().setup()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_absolute_output_file_defaults() {
|
||||
let expected = manifest_dir().join("index.node");
|
||||
let actual = Setup::options().absolute_output_file();
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_absolute_output_file_absolute_file() {
|
||||
let expected = PathBuf::from("/tmp/hello.node");
|
||||
let actual = Setup::options()
|
||||
.output_dir("/tmp/ignore/me")
|
||||
.output_file("/tmp/hello.node")
|
||||
.absolute_output_file();
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_absolute_output_file_absolute_dir() {
|
||||
let expected = PathBuf::from("/tmp/index.node");
|
||||
let actual = Setup::options().output_dir("/tmp").absolute_output_file();
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_absolute_output_file_relative_dir() {
|
||||
let expected = manifest_dir().join("lib").join("index.node");
|
||||
let actual = Setup::options().output_dir("lib").absolute_output_file();
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_absolute_output_file_relative_file() {
|
||||
let expected = manifest_dir().join("lib.node");
|
||||
let actual = Setup::options()
|
||||
.output_file("lib.node")
|
||||
.absolute_output_file();
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
[package]
|
||||
name = "neon-macros"
|
||||
version = "0.8.2"
|
||||
authors = ["Dave Herman <david.herman@gmail.com>"]
|
||||
description = "Procedural macros supporting Neon"
|
||||
repository = "https://github.com/neon-bindings/neon"
|
||||
license = "MIT/Apache-2.0"
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[features]
|
||||
napi = []
|
||||
|
||||
[dependencies]
|
||||
quote = "1"
|
||||
syn = { version = "1", features = ["full"] }
|
||||
@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2015 David Herman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@ -1,81 +0,0 @@
|
||||
pub(crate) fn main(
|
||||
_attr: proc_macro::TokenStream,
|
||||
item: proc_macro::TokenStream,
|
||||
) -> proc_macro::TokenStream {
|
||||
let input = syn::parse_macro_input!(item as syn::ItemFn);
|
||||
|
||||
let attrs = &input.attrs;
|
||||
let vis = &input.vis;
|
||||
let sig = &input.sig;
|
||||
let block = &input.block;
|
||||
let name = &sig.ident;
|
||||
|
||||
quote::quote!(
|
||||
#(#attrs) *
|
||||
#vis #sig {
|
||||
// Mark this function as a global constructor (like C++).
|
||||
#[allow(improper_ctypes)]
|
||||
#[cfg_attr(target_os = "linux", link_section = ".ctors")]
|
||||
#[cfg_attr(target_os = "android", link_section = ".ctors")]
|
||||
#[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
|
||||
#[cfg_attr(target_os = "ios", link_section = "__DATA,__mod_init_func")]
|
||||
#[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")]
|
||||
#[used]
|
||||
static __LOAD_NEON_MODULE: extern "C" fn() = {
|
||||
extern "C" fn __load_neon_module() {
|
||||
// Put everything else in the ctor fn so the user fn can't see it.
|
||||
#[repr(C)]
|
||||
struct __NodeModule {
|
||||
version: i32,
|
||||
flags: u32,
|
||||
dso_handle: *mut u8,
|
||||
filename: *const u8,
|
||||
register_func: Option<extern "C" fn(
|
||||
::neon::handle::Handle<::neon::types::JsObject>, *mut u8, *mut u8)>,
|
||||
context_register_func: Option<extern "C" fn(
|
||||
::neon::handle::Handle<::neon::types::JsObject>, *mut u8, *mut u8, *mut u8)>,
|
||||
modname: *const u8,
|
||||
priv_data: *mut u8,
|
||||
link: *mut __NodeModule
|
||||
}
|
||||
|
||||
// Mark as used during tests to suppress warnings
|
||||
#[cfg_attr(test, used)]
|
||||
static mut __NODE_MODULE: __NodeModule = __NodeModule {
|
||||
version: 0,
|
||||
flags: 0,
|
||||
dso_handle: 0 as *mut _,
|
||||
filename: b"neon_source.rs\0" as *const u8,
|
||||
register_func: Some(__register_neon_module),
|
||||
context_register_func: None,
|
||||
modname: b"neon_module\0" as *const u8,
|
||||
priv_data: 0 as *mut _,
|
||||
link: 0 as *mut _
|
||||
};
|
||||
|
||||
extern "C" fn __register_neon_module(
|
||||
m: ::neon::handle::Handle<::neon::types::JsObject>, _: *mut u8, _: *mut u8) {
|
||||
::neon::macro_internal::initialize_module(m, #name);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn node_module_register(module: *mut __NodeModule);
|
||||
}
|
||||
|
||||
// During tests, node is not available. Skip module registration.
|
||||
#[cfg(not(test))]
|
||||
unsafe {
|
||||
// Set the ABI version based on the NODE_MODULE_VERSION constant provided by the current node headers.
|
||||
__NODE_MODULE.version = ::neon::macro_internal::runtime::module::get_version();
|
||||
node_module_register(&mut __NODE_MODULE);
|
||||
}
|
||||
}
|
||||
|
||||
__load_neon_module
|
||||
};
|
||||
|
||||
#block
|
||||
}
|
||||
)
|
||||
.into()
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
//! Procedural macros supporting [Neon](https://docs.rs/neon/latest/neon/)
|
||||
|
||||
#[cfg(feature = "napi")]
|
||||
mod napi;
|
||||
#[cfg(feature = "napi")]
|
||||
use napi as macros;
|
||||
|
||||
#[cfg(not(feature = "napi"))]
|
||||
mod legacy;
|
||||
#[cfg(not(feature = "napi"))]
|
||||
use legacy as macros;
|
||||
|
||||
// Proc macro definitions must be in the root of the crate
|
||||
// Implementations are in the backend dependent module
|
||||
|
||||
#[proc_macro_attribute]
|
||||
/// Marks a function as the main entry point for initialization in
|
||||
/// a Neon module.
|
||||
///
|
||||
/// This attribute should only be used _once_ in a module and will
|
||||
/// be called each time the module is initialized in a context.
|
||||
///
|
||||
/// ```ignore
|
||||
/// #[neon::main]
|
||||
/// fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
||||
/// let version = cx.string("1.0.0");
|
||||
///
|
||||
/// cx.export_value("version", version)?;
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// If multiple functions are marked with `#[neon::main]`, there may be a compile error:
|
||||
///
|
||||
/// ```sh
|
||||
/// error: symbol `napi_register_module_v1` is already defined
|
||||
/// ```
|
||||
pub fn main(
|
||||
attr: proc_macro::TokenStream,
|
||||
item: proc_macro::TokenStream,
|
||||
) -> proc_macro::TokenStream {
|
||||
macros::main(attr, item)
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
pub(crate) fn main(
|
||||
_attr: proc_macro::TokenStream,
|
||||
item: proc_macro::TokenStream,
|
||||
) -> proc_macro::TokenStream {
|
||||
let input = syn::parse_macro_input!(item as syn::ItemFn);
|
||||
|
||||
let attrs = &input.attrs;
|
||||
let vis = &input.vis;
|
||||
let sig = &input.sig;
|
||||
let block = &input.block;
|
||||
let name = &sig.ident;
|
||||
|
||||
quote::quote!(
|
||||
#(#attrs) *
|
||||
#vis #sig {
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn napi_register_module_v1(
|
||||
env: ::neon::macro_internal::runtime::raw::Env,
|
||||
m: ::neon::macro_internal::runtime::raw::Local,
|
||||
) -> ::neon::macro_internal::runtime::raw::Local {
|
||||
::neon::macro_internal::initialize_module(
|
||||
env,
|
||||
::std::mem::transmute(m),
|
||||
#name,
|
||||
);
|
||||
|
||||
m
|
||||
}
|
||||
|
||||
#block
|
||||
}
|
||||
)
|
||||
.into()
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
[package]
|
||||
name = "neon-runtime"
|
||||
version = "0.8.2"
|
||||
authors = ["Dave Herman <david.herman@gmail.com>"]
|
||||
description = "Bindings to the Node.js native addon API, used by the Neon implementation."
|
||||
repository = "https://github.com/neon-bindings/neon"
|
||||
license = "MIT/Apache-2.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
cfg-if = "1.0.0"
|
||||
libloading = { version = "0.6.5", optional = true }
|
||||
neon-sys = { version = "=0.8.2", path = "../neon-sys", optional = true }
|
||||
smallvec = "1.4.2"
|
||||
|
||||
[dev-dependencies]
|
||||
nodejs-sys = "0.7.0" # Not strictly needed; just here for easy manual copying
|
||||
|
||||
[features]
|
||||
default = []
|
||||
napi = ["libloading"]
|
||||
napi-2 = ["napi"]
|
||||
napi-3 = ["napi-2"]
|
||||
napi-4 = ["napi-3"]
|
||||
napi-5 = ["napi-4"]
|
||||
napi-6 = ["napi-5"]
|
||||
napi-experimental = ["napi-6"]
|
||||
docs-only = ["neon-sys/docs-only"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = ["docs-only"]
|
||||
@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2015 David Herman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@ -1,23 +0,0 @@
|
||||
#[cfg(all(not(feature = "neon-sys"), not(feature = "napi")))]
|
||||
compile_error!(
|
||||
"The Neon runtime must have at least one of the `neon-sys` or `napi` backends enabled."
|
||||
);
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "napi")] {
|
||||
pub mod napi;
|
||||
}
|
||||
}
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "neon-sys")] {
|
||||
pub mod nan;
|
||||
// The legacy variant is the default API as long as it's present.
|
||||
pub use crate::nan::*;
|
||||
} else if #[cfg(feature = "napi")] {
|
||||
// The N-API variant is only the default API if the legacy variant is disabled.
|
||||
pub use crate::napi::*;
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
//! Facilities for working with `v8::Array`s.
|
||||
|
||||
/// Mutates the `out` argument provided to refer to a newly created `v8::Array`.
|
||||
pub use neon_sys::Neon_Array_New as new;
|
||||
|
||||
/// Gets the length of an `v8::Array`.
|
||||
pub use neon_sys::Neon_Array_Length as len;
|
||||
@ -1,8 +0,0 @@
|
||||
//! Facilities for working with `v8::ArrayBuffer`s.
|
||||
|
||||
/// Mutates the `out` argument provided to refer to a newly created `v8::ArrayBuffer` object.
|
||||
/// Returns `false` if the value couldn't be created.
|
||||
pub use neon_sys::Neon_ArrayBuffer_New as new;
|
||||
|
||||
/// Mutates the `base_out` and `size_out` arguments to access the data of a `v8::ArrayBuffer` object.
|
||||
pub use neon_sys::Neon_ArrayBuffer_Data as data;
|
||||
@ -1,12 +0,0 @@
|
||||
//! Facilities for working with `node::Buffer`s.
|
||||
|
||||
/// Mutates the `out` argument provided to refer to a newly created and zero-filled `node::Buffer` object.
|
||||
/// Returns `false` if the value couldn't be created.
|
||||
pub use neon_sys::Neon_Buffer_New as new;
|
||||
|
||||
/// Mutates the `out` argument provided to refer to a newly created `node::Buffer` object.
|
||||
/// Returns `false` if the value couldn't be created.
|
||||
pub use neon_sys::Neon_Buffer_Uninitialized as uninitialized;
|
||||
|
||||
/// Mutates the `base_out` and `size_out` arguments to access the data of a `node::Buffer` object.
|
||||
pub use neon_sys::Neon_Buffer_Data as data;
|
||||
@ -1,30 +0,0 @@
|
||||
//! Facilities for working with `v8::FunctionCallbackInfo` and getting the current `v8::Isolate`.
|
||||
|
||||
pub use neon_sys::CCallback;
|
||||
|
||||
/// Sets the return value of the function call.
|
||||
pub use neon_sys::Neon_Call_SetReturn as set_return;
|
||||
|
||||
/// Gets the isolate of the function call.
|
||||
pub use neon_sys::Neon_Call_GetIsolate as get_isolate;
|
||||
|
||||
/// Gets the current `v8::Isolate`.
|
||||
pub use neon_sys::Neon_Call_CurrentIsolate as current_isolate;
|
||||
|
||||
/// Indicates if the function call was invoked as a constructor.
|
||||
pub use neon_sys::Neon_Call_IsConstruct as is_construct;
|
||||
|
||||
/// Mutates the `out` argument provided to refer to the `v8::Local` handle value of the object
|
||||
/// the function is bound to.
|
||||
pub use neon_sys::Neon_Call_This as this;
|
||||
|
||||
/// Mutates the `out` argument provided to refer to the pointer value of the
|
||||
/// `v8::FunctionCallbackInfo` `Data`.
|
||||
pub use neon_sys::Neon_Call_Data as data;
|
||||
|
||||
/// Gets the number of arguments passed to the function.
|
||||
pub use neon_sys::Neon_Call_Length as len;
|
||||
|
||||
/// Mutates the `out` argument provided to refer to the `v8::Local` handle value of the `i`th
|
||||
/// argument passed to the function.
|
||||
pub use neon_sys::Neon_Call_Get as get;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user