Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Usage document doesn't say how to run output #485

Closed
floitschG opened this issue Apr 4, 2016 · 5 comments
Closed

Usage document doesn't say how to run output #485

floitschG opened this issue Apr 4, 2016 · 5 comments

Comments

@floitschG
Copy link

The usage document explains how to compile an executable, but doesn't say how to run it.
Just pointing d8 at the generated file doesn't work.
The document also mentions --server, but my version (the most recent via pub global activate, or via git clone) doesn't support that option.

@vsmenon
Copy link
Contributor

vsmenon commented Apr 4, 2016

The usage doc is now out of date as of 0.1.22:

https://github.com/dart-lang/dev_compiler/blob/master/CHANGELOG.md

Both the server code and the node runner code have been removed while we rework the core compiler to be modularly invocable from bazel, etc. We may add them back in or use something like package:build if that makes sense.

You should still be able to point at an html file with a dart script and get a modified html file with js scripts.

@vsmenon
Copy link
Contributor

vsmenon commented Apr 21, 2016

I've marked that doc deprecated for now.

Whole program code has been removed from tip-of-tree. We're focused on modular compile right now. We can compile targets with DDC, but rely on other tools to link.

Here are some notes (assuming bash) on how to experiment with DDC code using node tools assuming you have ddc checked out at $DDC_PATH (you'll need to run pub get in there as well).

This is all experimental

(1) Download and build a nodejs v6.0 from here:

https://nodejs.org/download/rc/

Note, this is a release candidate. You probably don't want to remove any stable versions (e.g, v5 based). v6 is required for harmony / ES6 support.

(2) Create and cd into a test directory. Create a symlink to the node you built above (or just put it on your path).

(3) Create a node version of the dart_sdk:

dart $DDC_PATH/tool/build_sdk.dart --dart-sdk $DDC_PATH/gen/patched_sdk/ --modules node -o dart_sdk.js

(4) Define a node path (you can add other directories if you want to separate things out):

export NODE_PATH=.

(5) Compile a test file with a main entry point:

dart  $DDC_PATH/bin/dartdevc.dart compile --modules node -o hello.js hello.dart

Note, the hello.js built here is not fully linked. It loads the SDK via a require call.

(6) Run it via your node built in step 1:

./node -e 'require("hello").hello.main()'

(7) Compile multiple libraries using summaries. E.g., write a world.dart that imports hello.dart with it's own main. Step 5 above generated a summary (hello.sum) for hello.dart. Build world:

dart $DDC_PATH/bin/dartdevc.dart compile --modules node -s hello.sum -o world.js world.dart

Run world just like hello above:

./node -e 'require("world").world.main()'

(8) Node modules do not run directly on the browser or v8. You can use a tool like browserify to build a linked javascript file that can:

Install:

sudo npm install -g browserify

and run:

echo 'require("world").world.main()' | browserify -d - > world.dart.js

The produced world.dart.js fully links all dependencies (dart_sdk, hello, and world) and executes world.main. It can be loaded via script tag and run in Chrome (stable or later).

@devoncarew
Copy link
Contributor

This is great info! Worth bumping up to a top-level markdown doc?

@vsmenon
Copy link
Contributor

vsmenon commented Apr 25, 2016

We should - and perhaps replace the Usage.md doc which is woefully out of date. Node v6 is scheduled to go stable tomorrow, so the instructions will get a bit easier.

@vsmenon
Copy link
Contributor

vsmenon commented Aug 14, 2016

I've updated the USAGE.md doc with the instructions here. We're still working on improving this - see #613.

@vsmenon vsmenon closed this as completed Aug 14, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants