Skip to content

Commit f057882

Browse files
committed
---
yaml --- r: 152876 b: refs/heads/try2 c: a548e81 h: refs/heads/master v: v3
1 parent f6c8d2b commit f057882

File tree

18 files changed

+244
-386
lines changed

18 files changed

+244
-386
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: deb6b04e91e9046b80f2ad7552d4aaf41fa78622
8+
refs/heads/try2: a548e8185a945e993e58f4cacf116943907cd29e
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/guide.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,26 +264,139 @@ projects.
264264

265265
## Hello, Cargo!
266266

267+
[Cargo](http://crates.io) is a tool that Rustaceans use to help manage their
268+
Rust projects. Cargo is currently in an alpha state, just like Rust, and so it
269+
is still a work in progress. However, it is already good enough to use for many
270+
Rust projects, and so it is assumed that Rust projects will use Cargo from the
271+
beginning.
267272

273+
Programmers love car analogies, so I've got a good one for you to think about
274+
the relationship between `cargo` and `rustc`: `rustc` is like a car, and
275+
`cargo` is like a robotic driver. You can drive your car yourself, of course,
276+
but isn't it just easier to let a computer drive it for you?
268277

278+
Anyway, Cargo manages three things: building your code, downloading the
279+
dependencies your code needs, and building the dependencies your code needs.
280+
At first, your program doesn't have any dependencies, so we'll only be using
281+
the first part of its functionality. Eventually, we'll add more. Since we
282+
started off by using Cargo, it'll be easy to add later.
269283

284+
Let's convert Hello World to Cargo. The first thing we need to do is install
285+
it. To do this, we need to build it from source. There are no binaries yet.
270286

287+
First, let's go back to our projects directory. We don't want Cargo to
288+
live in our project!
271289

290+
```{bash}
291+
$ cd ..
292+
```
293+
294+
Next, we need these commands:
295+
296+
```{bash}
297+
$ git clone --recursive https://github.com/rust-lang/cargo
298+
$ cd cargo
299+
$ make
300+
$ make install # may need sudo or admin permissions
301+
```
302+
303+
The `--recursive` downloads Cargo's own dependencies. You can't use Cargo to
304+
fetch dependencies until you have Cargo installed!
305+
306+
Let's see if that worked. Try this:
307+
308+
```{bash}
309+
$ cargo
310+
Commands:
311+
build # compile the current project
312+
313+
Options (for all commands):
314+
315+
-v, [--verbose]
316+
-h, [--help]
317+
```
318+
319+
If you see this output when you run `cargo`, congrats! Cargo is working. If
320+
not, please [open an Issue](https://github.com/rust-lang/cargo/issues/new) or
321+
drop by the Rust IRC, and we can help you out.
272322

323+
Let's move back into our `hello_world` directory now:
273324

325+
```{bash}
326+
$ cd .. # move back up into projects
327+
$ cd hello_world # move into hello_world
328+
```
329+
330+
To Cargo-ify our project, we need to do two things: Make a `Cargo.toml`
331+
configuration file, and put our source file in the right place. Let's
332+
do that part first:
333+
334+
```{bash}
335+
$ mkdir src
336+
$ mv hello_world.rs src/hello_world.rs
337+
```
338+
339+
Cargo expects your source files to live inside a `src` directory. That leaves
340+
the top level for other things, like READMEs, licence information, and anything
341+
not related to your code. Cargo helps us keep our projects nice and tidy. A
342+
place for everything, and everything in its place.
274343

344+
Next, our configuration file:
275345

346+
```{bash}
347+
$ editor Cargo.toml
348+
```
276349

350+
Make sure to get this name right: you need the capital `C`!
277351

352+
Put this inside:
278353

354+
```
355+
[package]
279356
357+
name = "hello_world"
358+
version = "0.1.0"
359+
authors = [ "[email protected]" ]
280360
361+
[[bin]]
281362
363+
name = "hello_world"
364+
```
282365

366+
This file is in the [TOML](https://github.com/toml-lang/toml) format. Let's let
367+
it explain itself to you:
283368

369+
> TOML aims to be a minimal configuration file format that's easy to read due
370+
> to obvious semantics. TOML is designed to map unambiguously to a hash table.
371+
> TOML should be easy to parse into data structures in a wide variety of
372+
> languages.
284373
374+
TOML is very similar to INI, but with some extra goodies.
285375

376+
Anyway, there are two **table**s in this file: `package` and `bin`. The first
377+
tells Cargo metadata about your package. The second tells Cargo that we're
378+
interested in building a binary, not a library (though we could do both!), as
379+
well as what it is named.
286380

381+
Once you have this file in place, we should be ready to build! Try this:
382+
383+
```{bash}
384+
$ cargo build
385+
Compiling hello_world v0.1.0 (file:/home/yourname/projects/hello_world)
386+
$ ./target/hello_world
387+
Hello, world!
388+
```
287389

390+
Bam! We build our project with `cargo build`, and run it with
391+
`./target/hello_world`. This hasn't bought us a whole lot over our simple use
392+
of `rustc`, but think about the future: when our project has more tha one file,
393+
we would need to call `rustc` twice, and pass it a bunch of options to tell it
394+
to build everything together. With Cargo, as our project grows, we can just
395+
`cargo build` and it'll work the right way.
288396

397+
That's it! We've successfully built `hello_world` with Cargo. Even though our
398+
program is simple, it's using all of the real tooling that you'll use for the
399+
rest of your Rust career.
289400

401+
Next, we'll learn more about Rust itself, by starting to write a more complicated
402+
program. We hope you want to do more with Rust than just print "Hello, world!"

branches/try2/src/libgreen/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ pub fn start(argc: int, argv: **u8,
299299
let mut ret = None;
300300
simple::task().run(|| {
301301
ret = Some(run(event_loop_factory, main.take_unwrap()));
302-
}).destroy();
302+
});
303303
// unsafe is ok b/c we're sure that the runtime is gone
304304
unsafe { rt::cleanup() }
305305
ret.unwrap()

branches/try2/src/libgreen/task.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extern fn bootstrap_green_task(task: uint, code: *(), env: *()) -> ! {
110110
// requested. This is the "try/catch" block for this green task and
111111
// is the wrapper for *all* code run in the task.
112112
let mut start = Some(start);
113-
let task = task.swap().run(|| start.take_unwrap()()).destroy();
113+
let task = task.swap().run(|| start.take_unwrap()());
114114

115115
// Once the function has exited, it's time to run the termination
116116
// routine. This means we need to context switch one more time but
@@ -120,7 +120,7 @@ extern fn bootstrap_green_task(task: uint, code: *(), env: *()) -> ! {
120120
// this we could add a `terminate` function to the `Runtime` trait
121121
// in libstd, but that seems less appropriate since the coversion
122122
// method exists.
123-
GreenTask::convert(task).terminate();
123+
GreenTask::convert(task).terminate()
124124
}
125125

126126
impl GreenTask {

branches/try2/src/libnative/io/process.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,6 @@ fn spawn_process_os(cfg: ProcessConfig,
533533

534534
let dirp = cfg.cwd.map(|c| c.with_ref(|p| p)).unwrap_or(ptr::null());
535535

536-
let cfg = unsafe {
537-
mem::transmute::<ProcessConfig,ProcessConfig<'static>>(cfg)
538-
};
539-
540536
with_envp(cfg.env, proc(envp) {
541537
with_argv(cfg.program, cfg.args, proc(argv) unsafe {
542538
let (mut input, mut output) = try!(pipe());

branches/try2/src/libnative/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,13 @@ pub fn start(argc: int, argv: **u8, main: proc()) -> int {
134134
let mut main = Some(main);
135135
let mut task = task::new((my_stack_bottom, my_stack_top));
136136
task.name = Some(str::Slice("<main>"));
137-
drop(task.run(|| {
137+
let t = task.run(|| {
138138
unsafe {
139139
rt::stack::record_stack_bounds(my_stack_bottom, my_stack_top);
140140
}
141141
exit_code = Some(run(main.take_unwrap()));
142-
}).destroy());
142+
});
143+
drop(t);
143144
unsafe { rt::cleanup(); }
144145
// If the exit code wasn't set, then the task block must have failed.
145146
return exit_code.unwrap_or(rt::DEFAULT_ERROR_CODE);

branches/try2/src/libnative/task.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ pub fn spawn_opts(opts: TaskOpts, f: proc():Send) {
9292
let mut f = Some(f);
9393
let mut task = task;
9494
task.put_runtime(ops);
95-
drop(task.run(|| { f.take_unwrap()() }).destroy());
95+
let t = task.run(|| { f.take_unwrap()() });
96+
drop(t);
9697
bookkeeping::decrement();
9798
})
9899
}

branches/try2/src/librustc/middle/kind.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,8 @@ fn with_appropriate_checker(cx: &Context,
198198
let fty = ty::node_id_to_type(cx.tcx, id);
199199
match ty::get(fty).sty {
200200
ty::ty_closure(box ty::ClosureTy {
201-
store: ty::UniqTraitStore,
202-
bounds: mut bounds, ..
203-
}) => {
204-
// Procs can't close over non-static references!
205-
bounds.add(ty::BoundStatic);
206-
207-
b(|cx, fv| check_for_uniq(cx, fv, bounds))
208-
}
201+
store: ty::UniqTraitStore, bounds, ..
202+
}) => b(|cx, fv| check_for_uniq(cx, fv, bounds)),
209203

210204
ty::ty_closure(box ty::ClosureTy {
211205
store: ty::RegionTraitStore(region, _), bounds, ..

branches/try2/src/librustrt/local_heap.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,7 @@ impl LocalHeap {
110110
self.memory_region.free(alloc);
111111
}
112112

113-
/// Immortalize all pending allocations, forcing them to live forever.
114-
///
115-
/// This function will freeze all allocations to prevent all pending
116-
/// allocations from being deallocated. This is used in preparation for when
117-
/// a task is about to destroy TLD.
118-
pub unsafe fn immortalize(&mut self) {
113+
pub unsafe fn annihilate(&mut self) {
119114
let mut n_total_boxes = 0u;
120115

121116
// Pass 1: Make all boxes immortal.
@@ -127,17 +122,6 @@ impl LocalHeap {
127122
(*alloc).ref_count = RC_IMMORTAL;
128123
});
129124

130-
if debug_mem() {
131-
// We do logging here w/o allocation.
132-
rterrln!("total boxes annihilated: {}", n_total_boxes);
133-
}
134-
}
135-
136-
/// Continues deallocation of the all pending allocations in this arena.
137-
///
138-
/// This is invoked from the destructor, and requires that `immortalize` has
139-
/// been called previously.
140-
unsafe fn annihilate(&mut self) {
141125
// Pass 2: Drop all boxes.
142126
//
143127
// In this pass, unique-managed boxes may get freed, but not
@@ -158,6 +142,11 @@ impl LocalHeap {
158142
self.each_live_alloc(true, |me, alloc| {
159143
me.free(alloc);
160144
});
145+
146+
if debug_mem() {
147+
// We do logging here w/o allocation.
148+
rterrln!("total boxes annihilated: {}", n_total_boxes);
149+
}
161150
}
162151

163152
unsafe fn each_live_alloc(&mut self, read_next_before: bool,
@@ -181,7 +170,6 @@ impl LocalHeap {
181170

182171
impl Drop for LocalHeap {
183172
fn drop(&mut self) {
184-
unsafe { self.annihilate() }
185173
assert!(self.live_allocs.is_null());
186174
}
187175
}

0 commit comments

Comments
 (0)