Git Product home page Git Product logo

learnuv's Introduction

learnuv

Learn uv for fun and profit, a self guided workshop to the library that powers Node.js.

screenshot

Before You Start

Read the learnuv gitbook which explains some libuv and related C language concepts that will help you complete the exercises.

Installation

Requires Python 2.6 or 2.7 to be installed. If python is not in your path set the environment variable PYTHON to its location. For example on Windows: set PYTHON=C:\Python27\python.exe

git clone https://github.com/thlorenz/learnuv && cd learnuv
npm install

Getting Started

./learnuv help

Building

learnuv comes with build commands that you can use instead of the manual steps explained further below.

  • ./learnuv ninja Compile your sources with ninja, stored inside ./out/Debug
  • ./learnuv make Compile your sources with make, stored inside ./out/Debug
  • ./learnuv xcode Generate a learnuv Xcode project, named ./learnuv.xcodeproj

Windows Caveats

Ninja and Make do not work on windows except via cygwin.

Ninja

Highly recommended since it builds faster than any of the other options, so get ninja and do:

./gyp_learnuv.py -f ninja
ninja -C out/Debug
./out/Debug/01_system_info

Make

Works on Linux and OSX.

./gyp_learnuv.py -f make
make -C out
./out/Debug/01_system_info

Xcode

Works on OSX only. Highly recommended to ease debugging and code navigation.

./gyp_learnuv.py -f xcode
open learnuv.xcodeproj

Visual Studio

Works on Windows only. TODO need to adapt vcbuild.bat.

Running

./learnuv

License

MIT

learnuv's People

Contributors

b1r3k avatar dineshjoshi avatar ibykow avatar irnc avatar jondavidjohn avatar needforspeed avatar parachvte avatar paulfryzel avatar phillipj avatar sericaia avatar skeptomai avatar thlorenz avatar zealotous avatar

Stargazers

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

Watchers

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

learnuv's Issues

./learnuv ninja not found

./learnuv ninja

[email protected] ninja ~/learning/learnuv
./gyp_learnuv.py -f ninja && ninja -C out/Debug $CURRENT_TARGET

['-f', 'ninja', '/learning/learnuv/learnuv.gyp', '-I', '/learning/learnuv/deps/libuv/common.gypi', '--depth=.', '-Dgcc_version=62', '-Dclang=0', '-Dhost_arch=x64', '-Dtarget_arch=x64', '-Duv_library=static_library', '-Dcomponent=static_library', '-Droot=/home/mariano/learning/learnuv', '-Dmagic_file=/learning/learnuv/magic/file.txt', '-Dhome=/', '-Dlearnuv_config=~/.config/learnuv']

Usage: npm

where is one of:
access, adduser, bin, bugs, c, cache, completion, config,
ddp, dedupe, deprecate, dist-tag, docs, edit, explore, get,
help, help-search, i, init, install, install-test, it, link,
list, ln, login, logout, ls, outdated, owner, pack, ping,
prefix, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, tst, un, uninstall,
unpublish, unstar, up, update, v, version, view, whoami

npm -h quick help on
npm -l display full usage info
npm help search for help on
npm help npm involved overview

Specify configs in the ini-formatted file:
~/.npmrc
or on the command line via: npm --key value
Config info can be viewed via: npm help config

[email protected] ~/.nvm/versions/node/v7.4.0/lib/node_modules/npm

Does anybody have some help for this?

out of memory when trying to clone (large files in git history?)

When trying to clone this project I'm getting...

git clone https://github.com/thlorenz/learnuv && cd learnuv
Cloning into 'learnuv'...
fatal: Out of memory, malloc failed (tried to allocate 1024288000 bytes)
fatal: Not a git repository: '/home/meandave/Code/learnuv/.git'

I believe this means there are some REALLY large files in the git history?
I'm sure I'll find some other workaround, but thought you might want to go through
and prune out some of those large files.(if that is the issue)

uv.gyp not found

['-f', 'make', '/home/tom/Public/learnuv/learnuv.gyp', '--depth=.', '-Goutput_dir=/home/tom/Public/learnuv/out', '--generator-output', '/home/tom/Public/learnuv/out', '-Dgcc_version=48', '-Dclang=0', '-Dhost_arch=i686', '-Dtarget_arch=i686', '-Duv_library=static_library', '-Dcomponent=static_library', '-Droot=/home/tom/Public/learnuv', '-Dmagic_file=/home/tom/Public/learnuv/magic/file.txt', '-Dhome=/home/tom', '-Dlearnuv_config=/home/tom/.config/learnuv']
gyp: /home/tom/Public/learnuv/deps/libuv/uv.gyp not found (cwd: /home/tom/Public/learnuv) while loading dependencies of /home/tom/Public/learnuv/learnuv.gyp while trying to load /home/tom/Public/learnuv/learnuv.gyp
Error running GYP

where can i get deps/ ?

ERROR installing in windows

Hello, i trying to install into windows with nodejs v6, but i get this error, how can i fix it?:

[email protected] preinstall C:\Windows\System32\learnuv
python scripts/install-dependencies.py

python: can't open file 'scripts/install-dependencies.py': [Errno 2] No such file or directory

npm WARN [email protected] license should be a valid SPDX license expression
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\Program Files (x86)\nodejs\node.exe" "C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js" "install"
npm ERR! node v6.7.0
npm ERR! npm v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] preinstall: python scripts/install-dependencies.py
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] preinstall script 'python scripts/install-dependencies.py'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the learnuv package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! python scripts/install-dependencies.py
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs learnuv
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls learnuv
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! C:\Windows\System32\learnuv\npm-debug.log

Could I build on OSX without XCode?

Runnig ./learnuv make or ./learnuv ninja is always asking for XCode

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

libuv usage

I don't think rust is using libuv now, it seems they have moved to mio.

Please remove Mozilla's Rust language from What is libuv section.

Thank you.

Where is task.h?

It is included in learnuv.hbut both clang and I couldn't find it anywhere.

#include "task.h" /* MAKE_VALGRIND_HAPPY */

solution for 03_fs_readsync is not working

the solution to 03 in the repo is not working for me. it seems to be getting an extra newline in the output.

Adding this gets me past it but it's not very pretty

  char *e = strchr (buf, '\n');
  if (e) {
      *e = '\0';
  }

`gyp_learnuv.py` fails for both python2 and python3 on Ubuntu 20.04

$> python2.7 ./gyp_learnuv.py -f make                      
Traceback (most recent call last):
  File "./gyp_learnuv.py", line 93, in <module>
    (major, minor), is_clang = compiler_version()
ValueError: need more than 1 value to unpack
$> python3.8 ./gyp_learnuv.py -f make
  File "./gyp_learnuv.py", line 56
    print 'Error running GYP'
          ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Error running GYP')?

05_fs_readasync_context - pointer being freed was not allocated

The read_cb function provided for exercise 05 performs free(context->iov.base); which is trying to free a pointer which was not allocated with malloc, realloc nor calloc.

I couldn't fix this error yet, but still think it's worth sharing this as an issue in case someone already fixed it and could suggest it in this thread.

unclear how to build example

hi,

i was wondering how to build the first example to test my libuv learnings. what i tried was this on MacOS:

$ gcc -I deps/libuv/test/ -I deps/libuv/include/ -I deps/log src/01_system_info.c
Undefined symbols for architecture x86_64:
  "_uv_err_name", referenced from:
      _main in 01_system_info-fe7cb9.o
  "_uv_strerror", referenced from:
      _main in 01_system_info-fe7cb9.o
  "_uv_uptime", referenced from:
      _main in 01_system_info-fe7cb9.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

About items 'bufs' and 'bufsml[4]' in uv_fs_t

Hi, everybody.
Sorry to trouble you, but I got problem when I played with your 'games'.
When I running my program(even your exercise answers), they all got "segmentation fault", I tracked them and found it should be here:
/* 4. Report the contents of the buffer */
log_report("%s", read_req->bufs->base);
log_info("%s", read_req->bufs->base);

because when it come into the callback, read_req->bufs turned to NULL, but I can use
read_req->bufsml->base to make it work.

03_fs_readsync needs buffer length modification to run correctly.

I'm not sure if it's supposed to be left as an exercise to the user, but I had to make a small off-topic modification to the buffer allocation to make this work. The reason was that the buffer doesn't have a null terminator as created, and it needs one for the log_report() and log_info() calls.

I fixed it by adding this, but the null terminator could be added in other ways, I suppose:

  char buf[BUF_SIZE + 1];
  memset(buf, 0, sizeof(buf));

Can installation procedure be made simpler?

Awesome job on this workshopper. Have a question/suggestion regarding possibility to have it simple npm i -g learnuv since it can use node-gyp for building. AFAIK, it needs just adding proper install command and nodegyp flag set in package.json
What do you think about this?

You need to install gyp in build/gyp first. when run ./learnuv make

Env:

      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 18.04.6 LTS x86_64 
    .ossssssssssssssssssdMMMNysssso.       Host: Google Compute Engine 
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Kernel: 5.4.0-1106-gcp 
  +ssssssssshmydMMMMMMMNddddyssssssss+     Uptime: 4 mins 
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Packages: 698 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Shell: bash 4.4.20 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Terminal: /dev/pts/0 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   CPU: Intel Xeon (2) @ 2.199GHz 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   Memory: 284MiB / 3928MiB 

re4388001@instance-0:~/learnuv$ env | grep PY
PYTHON=/usr/bin/python


re4388001@instance-0:~/learnuv$ python --version
Python 2.7.17

Error reproduce:

  1. git clone the repo
  2. npm i
  3. ./learnuv and select the first one
  4. ./learnuv make
$ ./learnuv make

> [email protected] make /home/re4388/pjt/node/learnuv
> ./gyp_learnuv.py -f make && make -C out $CURRENT_TARGET

You need to install gyp in build/gyp first. See the README.
npm ERR! code ELIFECYCLE
npm ERR! errno 42
npm ERR! [email protected] make: `./gyp_learnuv.py -f make && make -C out $CURRENT_TARGET`
npm ERR! Exit status 42
npm ERR!
npm ERR! Failed at the [email protected] make script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/re4388/.npm/_logs/2023-09-03T01_17_58_172Z-debug.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.