2014-08-07 19:03:17 +08:00
![libuv][libuv_banner]
## Overview
2011-09-24 02:07:57 +08:00
2013-10-30 07:33:17 +08:00
libuv is a multi-platform support library with a focus on asynchronous I/O. It
2017-07-07 07:12:45 +08:00
was primarily developed for use by [Node.js][], but it's also
2014-11-21 22:43:12 +08:00
used by [Luvit ](http://luvit.io/ ), [Julia ](http://julialang.org/ ),
2022-01-07 10:45:31 +08:00
[uvloop ](https://github.com/MagicStack/uvloop ), and [others ](https://github.com/libuv/libuv/blob/v1.x/LINKS.md ).
2011-05-13 10:16:40 +08:00
2013-10-30 07:33:17 +08:00
## Feature highlights
2011-09-24 02:07:57 +08:00
2013-10-30 07:33:17 +08:00
* Full-featured event loop backed by epoll, kqueue, IOCP, event ports.
2011-09-24 02:07:57 +08:00
2013-10-30 07:33:17 +08:00
* Asynchronous TCP and UDP sockets
2011-09-24 02:07:57 +08:00
2013-10-30 07:33:17 +08:00
* Asynchronous DNS resolution
2011-09-24 02:07:57 +08:00
2013-10-30 07:33:17 +08:00
* Asynchronous file and file system operations
2011-09-24 11:23:41 +08:00
2013-10-30 07:33:17 +08:00
* File system events
2011-09-24 02:07:57 +08:00
2013-10-30 07:33:17 +08:00
* ANSI escape code controlled TTY
2011-09-24 02:07:57 +08:00
2013-10-30 07:33:17 +08:00
* IPC with socket sharing, using Unix domain sockets or named pipes (Windows)
2011-09-24 02:07:57 +08:00
2013-10-30 07:33:17 +08:00
* Child processes
2011-09-24 02:07:57 +08:00
2013-10-30 07:33:17 +08:00
* Thread pool
2011-09-24 02:07:57 +08:00
2013-10-30 07:33:17 +08:00
* Signal handling
2011-09-24 02:07:57 +08:00
2013-10-30 07:33:17 +08:00
* High resolution clock
2011-10-01 02:22:38 +08:00
2013-10-30 07:33:17 +08:00
* Threading and synchronization primitives
2011-09-24 02:07:57 +08:00
2014-09-20 01:37:55 +08:00
## Versioning
Starting with version 1.0.0 libuv follows the [semantic versioning ](http://semver.org/ )
2014-12-10 04:01:35 +08:00
scheme. The API change and backwards compatibility rules are those indicated by
2014-09-20 01:37:55 +08:00
SemVer. libuv will keep a stable ABI across major releases.
2011-09-24 02:07:57 +08:00
2016-10-25 10:13:07 +08:00
The ABI/API changes can be tracked [here ](http://abi-laboratory.pro/tracker/timeline/libuv/ ).
## Licensing
2023-05-17 18:06:26 +08:00
libuv is licensed under the MIT license. Check the [LICENSE ](LICENSE ) and
[LICENSE-extra ](LICENSE-extra ) files.
The documentation is licensed under the CC BY 4.0 license. Check the
[LICENSE-docs file ](LICENSE-docs ).
2016-10-25 10:13:07 +08:00
2012-10-07 05:04:30 +08:00
## Community
2021-07-26 15:59:29 +08:00
* [Support ](https://github.com/libuv/libuv/discussions )
2012-10-07 05:04:30 +08:00
* [Mailing list ](http://groups.google.com/group/libuv )
2011-09-24 02:07:57 +08:00
## Documentation
2017-05-31 01:19:11 +08:00
### Official documentation
2014-09-20 01:37:55 +08:00
Located in the docs/ subdirectory. It uses the [Sphinx ](http://sphinx-doc.org/ )
framework, which makes it possible to build the documentation in multiple
formats.
Show different supported building options:
2017-07-07 07:12:45 +08:00
```bash
$ make help
```
2014-09-20 01:37:55 +08:00
Build documentation as HTML:
2017-07-07 07:12:45 +08:00
```bash
$ make html
```
2014-09-20 01:37:55 +08:00
2016-05-17 06:25:23 +08:00
Build documentation as HTML and live reload it when it changes (this requires
sphinx-autobuild to be installed and is only supported on Unix):
2017-07-07 07:12:45 +08:00
```bash
$ make livehtml
```
2016-05-17 06:25:23 +08:00
2014-09-20 01:37:55 +08:00
Build documentation as man pages:
2017-07-07 07:12:45 +08:00
```bash
$ make man
```
2014-09-20 01:37:55 +08:00
Build documentation as ePub:
2017-07-07 07:12:45 +08:00
```bash
$ make epub
```
2014-09-20 01:37:55 +08:00
NOTE: Windows users need to use make.bat instead of plain 'make'.
Documentation can be browsed online [here ](http://docs.libuv.org ).
2015-05-06 15:46:15 +08:00
The [tests and benchmarks ](https://github.com/libuv/libuv/tree/master/test )
also serve as API specification and usage examples.
2014-09-20 01:37:55 +08:00
### Other resources
2014-01-01 02:33:54 +08:00
* [LXJS 2012 talk ](http://www.youtube.com/watch?v=nGn60vDSxQ4 )
— High-level introductory talk about libuv.
* [libuv-dox ](https://github.com/thlorenz/libuv-dox )
— Documenting types and methods of libuv, mostly by reading uv.h.
2014-11-21 22:43:12 +08:00
* [learnuv ](https://github.com/thlorenz/learnuv )
— Learn uv for fun and profit, a self guided workshop to libuv.
2011-09-24 02:07:57 +08:00
2015-05-06 15:46:15 +08:00
These resources are not handled by libuv maintainers and might be out of
date. Please verify it before opening new issues.
2015-08-06 03:17:46 +08:00
## Downloading
libuv can be downloaded either from the
[GitHub repository ](https://github.com/libuv/libuv )
or from the [downloads site ](http://dist.libuv.org/dist/ ).
Before verifying the git tags or signature files, importing the relevant keys
is necessary. Key IDs are listed in the
[MAINTAINERS ](https://github.com/libuv/libuv/blob/master/MAINTAINERS.md )
file, but are also available as git blob objects for easier use.
Importing a key the usual way:
2017-07-07 07:12:45 +08:00
```bash
$ gpg --keyserver pool.sks-keyservers.net --recv-keys AE9BC059
```
2015-08-06 03:17:46 +08:00
Importing a key from a git blob object:
2017-07-07 07:12:45 +08:00
```bash
$ git show pubkey-saghul | gpg --import
```
2015-08-06 03:17:46 +08:00
### Verifying releases
Git tags are signed with the developer's key, they can be verified as follows:
2017-07-07 07:12:45 +08:00
```bash
$ git verify-tag v1.6.1
```
2015-08-06 03:17:46 +08:00
Starting with libuv 1.7.0, the tarballs stored in the
2015-12-13 19:07:04 +08:00
[downloads site ](http://dist.libuv.org/dist/ ) are signed and an accompanying
2015-08-06 03:17:46 +08:00
signature file sit alongside each. Once both the release tarball and the
signature file are downloaded, the file can be verified as follows:
2017-07-07 07:12:45 +08:00
```bash
$ gpg --verify libuv-1.7.0.tar.gz.sign
```
2015-08-06 03:17:46 +08:00
2011-09-24 02:07:57 +08:00
## Build Instructions
2011-05-13 10:16:40 +08:00
2020-04-16 00:41:19 +08:00
For UNIX-like platforms, including macOS, there are two build methods:
autotools or [CMake][].
2013-02-21 04:12:18 +08:00
2020-04-16 00:41:19 +08:00
For Windows, [CMake][] is the only supported build method and has the
following prerequisites:
2013-02-21 04:12:18 +08:00
2020-04-16 00:41:19 +08:00
< details >
2019-05-16 01:24:08 +08:00
2017-07-07 07:12:45 +08:00
* One of:
* [Visual C++ Build Tools][]
* [Visual Studio 2015 Update 3][], all editions
including the Community edition (remember to select
"Common Tools for Visual C++ 2015" feature during installation).
* [Visual Studio 2017][], any edition (including the Build Tools SKU).
**Required Components:** "MSbuild", "VC++ 2017 v141 toolset" and one of the
Windows SDKs (10 or 8.1).
* Basic Unix tools required for some tests,
[Git for Windows][] includes Git Bash
and tools which can be included in the global `PATH` .
2020-04-16 00:41:19 +08:00
< / details >
2011-08-09 05:14:47 +08:00
2020-04-16 00:41:19 +08:00
To build with autotools:
2013-01-22 23:21:25 +08:00
2017-07-07 07:12:45 +08:00
```bash
2020-04-16 00:41:19 +08:00
$ sh autogen.sh
$ ./configure
$ make
$ make check
$ make install
2017-07-07 07:12:45 +08:00
```
2013-01-22 23:21:25 +08:00
2020-04-16 00:41:19 +08:00
To build with [CMake][]:
2016-04-01 17:19:19 +08:00
2017-07-07 07:12:45 +08:00
```bash
2020-04-16 00:41:19 +08:00
$ mkdir -p build
2016-04-01 17:19:19 +08:00
2020-04-16 00:41:19 +08:00
$ (cd build & & cmake .. -DBUILD_TESTING=ON) # generate project with tests
$ cmake --build build # add `-j <n>` with cmake >= 3.12
2014-11-21 22:43:12 +08:00
2020-04-16 00:41:19 +08:00
# Run tests:
$ (cd build & & ctest -C Debug --output-on-failure)
2013-10-30 07:33:17 +08:00
2020-04-16 00:41:19 +08:00
# Or manually run tests:
$ build/uv_run_tests # shared library build
$ build/uv_run_tests_a # static library build
```
To cross-compile with [CMake][] (unsupported but generally works):
2011-08-09 05:14:47 +08:00
2017-07-07 07:12:45 +08:00
```bash
2020-04-16 00:41:19 +08:00
$ cmake ../.. \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_SYSTEM_VERSION=6.1 \
-DCMAKE_C_COMPILER=i686-w64-mingw32-gcc
2017-07-07 07:12:45 +08:00
```
2014-01-28 01:30:51 +08:00
2020-04-16 00:41:19 +08:00
### Install with Homebrew
2014-11-21 22:43:12 +08:00
2017-07-07 07:12:45 +08:00
```bash
$ brew install --HEAD libuv
```
2014-11-21 22:43:12 +08:00
2014-01-28 01:30:51 +08:00
Note to OS X users:
Make sure that you specify the architecture you wish to build for in the
"ARCHS" flag. You can specify more than one by delimiting with a space
(e.g. "x86_64 i386").
2011-08-09 05:14:47 +08:00
2023-05-17 18:06:26 +08:00
### Install with vcpkg
```bash
$ git clone https://github.com/microsoft/vcpkg.git
$ ./bootstrap-vcpkg.bat # for powershell
$ ./bootstrap-vcpkg.sh # for bash
$ ./vcpkg install libuv
```
2013-12-14 02:35:09 +08:00
### Running tests
2020-03-12 00:36:48 +08:00
Some tests are timing sensitive. Relaxing test timeouts may be necessary
on slow or overloaded machines:
```bash
2020-04-16 00:41:19 +08:00
$ env UV_TEST_TIMEOUT_MULTIPLIER=2 build/uv_run_tests # 10s instead of 5s
2020-03-12 00:36:48 +08:00
```
2018-09-21 22:14:00 +08:00
#### Run one test
The list of all tests is in `test/test-list.h` .
2020-04-16 00:41:19 +08:00
This invocation will cause the test driver to fork and execute `TEST_NAME` in
a child process:
2018-09-21 22:14:00 +08:00
```bash
2020-04-16 00:41:19 +08:00
$ build/uv_run_tests_a TEST_NAME
2018-09-21 22:14:00 +08:00
```
2020-04-16 00:41:19 +08:00
This invocation will cause the test driver to execute the test in
the same process:
2018-09-21 22:14:00 +08:00
```bash
2020-04-16 00:41:19 +08:00
$ build/uv_run_tests_a TEST_NAME TEST_NAME
2018-09-21 22:14:00 +08:00
```
#### Debugging tools
2020-04-16 00:41:19 +08:00
When running the test from within the test driver process
(`build/uv_run_tests_a TEST_NAME TEST_NAME`), tools like gdb and valgrind
work normally.
When running the test from a child of the test driver process
(`build/uv_run_tests_a TEST_NAME`), use these tools in a fork-aware manner.
2018-09-21 22:14:00 +08:00
##### Fork-aware gdb
Use the [follow-fork-mode ](https://sourceware.org/gdb/onlinedocs/gdb/Forks.html ) setting:
```
2020-04-16 00:41:19 +08:00
$ gdb --args build/uv_run_tests_a TEST_NAME
2018-09-21 22:14:00 +08:00
(gdb) set follow-fork-mode child
...
```
##### Fork-aware valgrind
Use the `--trace-children=yes` parameter:
```bash
2020-04-16 00:41:19 +08:00
$ valgrind --trace-children=yes -v --tool=memcheck --leak-check=full --track-origins=yes --leak-resolution=high --show-reachable=yes --log-file=memcheck-%p.log build/uv_run_tests_a TEST_NAME
2018-09-21 22:14:00 +08:00
```
### Running benchmarks
See the section on running tests.
2020-04-16 00:41:19 +08:00
The benchmark driver is `./uv_run_benchmarks_a` and the benchmarks are
listed in `test/benchmark-list.h` .
2018-09-21 22:14:00 +08:00
2011-09-24 02:07:57 +08:00
## Supported Platforms
2011-05-13 10:16:40 +08:00
2016-10-25 10:13:07 +08:00
Check the [SUPPORTED_PLATFORMS file ](SUPPORTED_PLATFORMS.md ).
2015-06-04 03:18:55 +08:00
2021-02-14 02:03:10 +08:00
### `-fno-strict-aliasing`
It is recommended to turn on the `-fno-strict-aliasing` compiler flag in
projects that use libuv. The use of ad hoc "inheritance" in the libuv API
may not be safe in the presence of compiler optimizations that depend on
strict aliasing.
MSVC does not have an equivalent flag but it also does not appear to need it
at the time of writing (December 2019.)
2015-06-04 03:18:55 +08:00
### AIX Notes
2019-09-10 01:08:37 +08:00
AIX compilation using IBM XL C/C++ requires version 12.1 or greater.
2015-06-04 03:18:55 +08:00
AIX support for filesystem events requires the non-default IBM `bos.ahafs`
package to be installed. This package provides the AIX Event Infrastructure
that is detected by `autoconf` .
[IBM documentation ](http://www.ibm.com/developerworks/aix/library/au-aix_event_infrastructure/ )
describes the package in more detail.
2018-05-08 06:36:08 +08:00
### z/OS Notes
2021-07-26 15:59:29 +08:00
z/OS compilation requires [ZOSLIB ](https://github.com/ibmruntimes/zoslib ) to be installed. When building with [CMake][], use the flag `-DZOSLIB_DIR` to specify the path to [ZOSLIB ](https://github.com/ibmruntimes/zoslib ):
```bash
$ (cd build & & cmake .. -DBUILD_TESTING=ON -DZOSLIB_DIR=/path/to/zoslib)
$ cmake --build build
```
2018-05-08 06:36:08 +08:00
z/OS creates System V semaphores and message queues. These persist on the system
after the process terminates unless the event loop is closed.
Use the `ipcrm` command to manually clear up System V resources.
2014-02-27 10:08:30 +08:00
## Patches
2013-12-14 02:35:09 +08:00
See the [guidelines for contributing][].
2020-04-16 00:41:19 +08:00
[CMake]: https://cmake.org/
2013-07-17 03:04:31 +08:00
[node.js]: http://nodejs.org/
2014-11-27 05:37:41 +08:00
[guidelines for contributing]: https://github.com/libuv/libuv/blob/master/CONTRIBUTING.md
[libuv_banner]: https://raw.githubusercontent.com/libuv/libuv/master/img/banner.png
2018-08-17 10:14:55 +08:00
[Visual C++ Build Tools]: https://visualstudio.microsoft.com/visual-cpp-build-tools/
2017-07-07 07:12:45 +08:00
[Visual Studio 2015 Update 3]: https://www.visualstudio.com/vs/older-downloads/
[Visual Studio 2017]: https://www.visualstudio.com/downloads/
[Git for Windows]: http://git-scm.com/download/win