Skip to content

Commit 14ae47a

Browse files
committed
---
yaml --- r: 80599 b: refs/heads/auto c: cf2253b h: refs/heads/master i: 80597: e16e8bf 80595: 1e1b2fe 80591: 87b5329 v: v3
1 parent 45a74f0 commit 14ae47a

File tree

14 files changed

+302
-59
lines changed

14 files changed

+302
-59
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 876cb76f1be63da0756a106ba743a617a5dfb2c8
16+
refs/heads/auto: cf2253ba3fb24ef3ab466b79e199dd2130a1e9c2
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/Makefile.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ CSREQ$(1)_T_$(2)_H_$(3) = \
442442
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
443443
$$(HBIN$(1)_H_$(3))/rustpkg$$(X_$(3)) \
444444
$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
445-
$$(HBIN$(1)_H_$(3))/rustdoc_ng$$(X_$(3)) \
446445
$$(HBIN$(1)_H_$(3))/rusti$$(X_$(3)) \
447446
$$(HBIN$(1)_H_$(3))/rust$$(X_$(3)) \
448447
$$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTPKG_$(3)) \

branches/auto/doc/tutorial-rustpkg.md

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
% Rust Packaging Tutorial
2+
3+
# Introduction
4+
5+
Sharing is caring. Rust comes with a tool, `rustpkg`, which allows you to
6+
package up your Rust code and share it with other people. This tutorial will
7+
get you started on all of the concepts and commands you need to give the gift
8+
of Rust code to someone else.
9+
10+
## Installing External Packages
11+
12+
First, let's try to use an external package somehow. I've made a sample package
13+
called `hello` to demonstrate how to do so. Here's how `hello` is used:
14+
15+
~~~~
16+
extern mod hello;
17+
18+
fn main() {
19+
hello::world();
20+
}
21+
~~~~
22+
23+
Easy! But if you try to compile this, you'll get an error:
24+
25+
~~~~ {.notrust}
26+
$ rustc main.rs
27+
main.rs:1:0: 1:17 error: can't find crate for `hello`
28+
main.rs:1 extern mod hello;
29+
^~~~~~~~~~~~~~~~~
30+
31+
~~~~
32+
33+
This makes sense, as we haven't gotten it from anywhere yet! Luckily for us,
34+
`rustpkg` has an easy way to fetch others' code: the `install` command. It's
35+
used like this:
36+
37+
~~~ {.notrust}
38+
$ rustpkg install pkg_id
39+
~~~
40+
41+
This will install a package named 'pkg_id' into your current Rust environment.
42+
I called it 'pkg_id' in this example because `rustpkg` calls this a 'package
43+
identifier.' When using it with an external package like this, it's often a
44+
URI fragment. You see, Rust has no central authority for packages. You can
45+
build your own `hello` library if you want, and that's fine. We'd both host
46+
them in different places and different projects would rely on whichever version
47+
they preferred.
48+
49+
To install the `hello` library, simply run this in your terminal:
50+
51+
~~~ {.notrust}
52+
$ rustpkg install github.com/steveklabnik/hello
53+
~~~
54+
55+
You should see a message that looks like this:
56+
57+
~~~ {.notrust}
58+
note: Installed package github.com/steveklabnik/hello-0.1 to /some/path/.rust
59+
~~~
60+
61+
Now, compiling our example should work:
62+
63+
~~~ {.notrust}
64+
$ rustc main.rs
65+
$ ./main
66+
Hello, world.
67+
~~~
68+
69+
Simple! That's all it takes.
70+
71+
## Workspaces
72+
73+
Before we can talk about how to make packages of your own, you have to
74+
understand the big concept with `rustpkg`: workspaces. A 'workspace' is simply
75+
a directory that has certain sub-directories that `rustpkg` expects. Different
76+
Rust projects will go into different workspaces.
77+
78+
A workspace consists of any directory that has the following
79+
directories:
80+
81+
* `src`: The directory where all the source code goes.
82+
* `build`: This directory contains all of the build output.
83+
* `lib`: The directory where any libraries distributed with the package go.
84+
* `bin`: This directory holds any binaries distributed with the package.
85+
86+
There are also default file names you'll want to follow as well:
87+
88+
* `main.rs`: A file that's going to become an executable.
89+
* `lib.rs`: A file that's going to become a library.
90+
91+
## Building your own Package
92+
93+
Now that you've got workspaces down, let's build your own copy of `hello`. Go
94+
to wherever you keep your personal projects, and let's make all of the
95+
directories we'll need. I'll refer to this personal project directory as
96+
`~/src` for the rest of this tutorial.
97+
98+
### Creating our workspace
99+
100+
~~~ {.notrust}
101+
$ cd ~/src
102+
$ mkdir -p hello/src/hello
103+
$ cd hello
104+
~~~
105+
106+
Easy enough! Let's do one or two more things that are nice to do:
107+
108+
~~~ {.notrust}
109+
$ git init .
110+
$ cat > README.md
111+
# hello
112+
113+
A simple package for Rust.
114+
115+
## Installation
116+
117+
```
118+
$ rustpkg install github.com/YOUR_USERNAME/hello
119+
```
120+
^D
121+
$ cat > .gitignore
122+
.rust
123+
build
124+
^D
125+
$ git commit -am "Initial commit."
126+
~~~
127+
128+
If you're not familliar with the `cat >` idiom, it will make files with the
129+
text you type inside. Control-D (`^D`) ends the text for the file.
130+
131+
Anyway, we've got a README and a `.gitignore`. Let's talk about that
132+
`.gitignore` for a minute: we are ignoring two directories, `build` and
133+
`.rust`. `build`, as we discussed earlier, is for build artifacts, and we don't
134+
want to check those into a repository. `.rust` is a directory that `rustpkg`
135+
uses to keep track of its own settings, as well as the source code of any other
136+
external packages that this workspace uses. This is where that `rustpkg
137+
install` puts all of its files. Those are also not to go into our repository,
138+
so we ignore it all as well.
139+
140+
Next, let's add a source file:
141+
142+
~~~
143+
#[desc = "A hello world Rust package."];
144+
#[license = "MIT"];
145+
146+
pub fn world() {
147+
println("Hello, world.");
148+
}
149+
~~~
150+
151+
Put this into `src/hello/lib.rs`. Let's talk about each of these attributes:
152+
153+
### Crate attributes for packages
154+
155+
`license` is equally simple: the license we want this code to have. I chose MIT
156+
here, but you should pick whatever license makes the most sense for you.
157+
158+
`desc` is a description of the package and what it does. This should just be a
159+
sentence or two.
160+
161+
### Building your package
162+
163+
Building your package is simple:
164+
165+
~~~ {.notrust}
166+
$ rustpkg build hello
167+
~~~
168+
169+
This will compile `src/hello/lib.rs` into a library. After this process
170+
completes, you'll want to check out `build`:
171+
172+
~~~ {.notrust}
173+
$ ls build/x86_64-unknown-linux-gnu/hello/
174+
libhello-ed8619dad9ce7d58-0.1.0.so
175+
~~~
176+
177+
This directory naming structure is called a 'build triple,' and is because I'm
178+
on 64 bit Linux. Yours may differ based on platform.
179+
180+
You'll also notice that `src/hello/lib.rs` turned into
181+
`libhello-ed8619dad9ce7d58-0.1.0.so`. This is a simple combination of the
182+
library name, a hash of its content, and the version.
183+
184+
Now that your library builds, you'll want to commit:
185+
186+
~~~ {.notrust}
187+
$ git add src
188+
$ git commit -m "Adding source code."
189+
~~~
190+
191+
If you're using GitHub, after creating the project, do this:
192+
193+
~~~ {.notrust}
194+
$ git remote add origin [email protected]:YOUR_USERNAME/hello.git
195+
$ git push origin -u master
196+
~~~
197+
198+
Now you can install and use it! Go anywhere else in your filesystem:
199+
200+
~~~ {.notrust}
201+
$ cd ~/src/foo
202+
$ rustpkg install github/YOUR_USERNAME/hello
203+
WARNING: The Rust package manager is experimental and may be unstable
204+
note: Installed package github.com/YOUR_USERNAME/hello-0.1 to /home/yourusername/src/hello/.rust
205+
~~~
206+
207+
That's it!
208+
209+
## More resources
210+
211+
There's a lot more going on with `rustpkg`, this is just to get you started.
212+
Check out [the rustpkg manual](rustpkg.html) for the full details on how to
213+
customize `rustpkg`.
214+
215+
A tag was created on GitHub specifically for `rustpkg`-related issues. You can
216+
[see all the Issues for rustpkg
217+
here](https://github.com/mozilla/rust/issues?direction=desc&labels=A-pkg&sort=created&state=open),
218+
with bugs as well as new feature plans. `rustpkg` is still under development,
219+
and so may be a bit flaky at the moment.
220+
221+
You may also want to check out [this blog
222+
post](http://tim.dreamwidth.org/1820526.html), which contains some of the early
223+
design decisions and justifications.

branches/auto/doc/tutorial-tasks.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@ concurrency at this writing:
4747

4848
* [`std::task`] - All code relating to tasks and task scheduling,
4949
* [`std::comm`] - The message passing interface,
50-
* [`extra::comm`] - Additional messaging types based on `std::comm`,
50+
* [`std::pipes`] - The underlying messaging infrastructure,
51+
* [`extra::comm`] - Additional messaging types based on `std::pipes`,
5152
* [`extra::sync`] - More exotic synchronization tools, including locks,
5253
* [`extra::arc`] - The Arc (atomically reference counted) type,
5354
for safely sharing immutable data,
5455
* [`extra::future`] - A type representing values that may be computed concurrently and retrieved at a later time.
5556

5657
[`std::task`]: std/task.html
5758
[`std::comm`]: std/comm.html
59+
[`std::pipes`]: std/pipes.html
5860
[`extra::comm`]: extra/comm.html
5961
[`extra::sync`]: extra/sync.html
6062
[`extra::arc`]: extra/arc.html
@@ -123,7 +125,7 @@ receiving messages. Pipes are low-level communication building-blocks and so
123125
come in a variety of forms, each one appropriate for a different use case. In
124126
what follows, we cover the most commonly used varieties.
125127

126-
The simplest way to create a pipe is to use the `comm::stream`
128+
The simplest way to create a pipe is to use the `pipes::stream`
127129
function to create a `(Port, Chan)` pair. In Rust parlance, a *channel*
128130
is a sending endpoint of a pipe, and a *port* is the receiving
129131
endpoint. Consider the following example of calculating two results

branches/auto/doc/tutorial.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,13 +2979,15 @@ tutorials on individual topics.
29792979
* [The foreign function interface][ffi]
29802980
* [Containers and iterators](tutorial-container.html)
29812981
* [Error-handling and Conditions](tutorial-conditions.html)
2982+
* [Packaging up Rust code](rustpkg)
29822983

29832984
There is further documentation on the [wiki], however those tend to be even more out of date as this document.
29842985

29852986
[borrow]: tutorial-borrowed-ptr.html
29862987
[tasks]: tutorial-tasks.html
29872988
[macros]: tutorial-macros.html
29882989
[ffi]: tutorial-ffi.html
2990+
[rustpkg]: tutorial-rustpkg.html
29892991

29902992
[wiki]: https://github.com/mozilla/rust/wiki/Docs
29912993

branches/auto/mk/clean.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ clean$(1)_H_$(2):
6868
$(Q)rm -f $$(HBIN$(1)_H_$(2))/rustpkg$(X_$(2))
6969
$(Q)rm -f $$(HBIN$(1)_H_$(2))/serializer$(X_$(2))
7070
$(Q)rm -f $$(HBIN$(1)_H_$(2))/rustdoc$(X_$(2))
71-
$(Q)rm -f $$(HBIN$(1)_H_$(2))/rustdoc_ng$(X_$(2))
7271
$(Q)rm -f $$(HBIN$(1)_H_$(2))/rusti$(X_$(2))
7372
$(Q)rm -f $$(HBIN$(1)_H_$(2))/rust$(X_$(2))
7473
$(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_LIBRUSTPKG_$(2))
@@ -106,7 +105,6 @@ clean$(1)_T_$(2)_H_$(3):
106105
$(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/rustpkg$(X_$(2))
107106
$(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/serializer$(X_$(2))
108107
$(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/rustdoc$(X_$(2))
109-
$(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/rustdoc_ng$(X_$(2))
110108
$(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/rusti$(X_$(2))
111109
$(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/rust$(X_$(2))
112110
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTPKG_$(2))

branches/auto/mk/dist.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ PKG_FILES := \
3939
libsyntax \
4040
rt \
4141
librustdoc \
42-
rustdoc_ng \
4342
rustllvm \
4443
snapshots.txt \
4544
test) \

branches/auto/mk/install.mk

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ install-host: $(CSREQ$(ISTAGE)_T_$(CFG_BUILD_TRIPLE)_H_$(CFG_BUILD_TRIPLE))
140140
$(Q)$(call INSTALL,$(HB2),$(PHB),rustc$(X_$(CFG_BUILD_TRIPLE)))
141141
$(Q)$(call INSTALL,$(HB2),$(PHB),rustpkg$(X_$(CFG_BUILD_TRIPLE)))
142142
$(Q)$(call INSTALL,$(HB2),$(PHB),rustdoc$(X_$(CFG_BUILD_TRIPLE)))
143-
$(Q)$(call INSTALL,$(HB2),$(PHB),rustdoc_ng$(X_$(CFG_BUILD_TRIPLE)))
144143
$(Q)$(call INSTALL,$(HB2),$(PHB),rusti$(X_$(CFG_BUILD_TRIPLE)))
145144
$(Q)$(call INSTALL,$(HB2),$(PHB),rust$(X_$(CFG_BUILD_TRIPLE)))
146145
$(Q)$(call INSTALL_LIB,$(STDLIB_GLOB_$(CFG_BUILD_TRIPLE)))
@@ -172,7 +171,6 @@ uninstall:
172171
$(Q)rm -f $(PHB)/rusti$(X_$(CFG_BUILD_TRIPLE))
173172
$(Q)rm -f $(PHB)/rust$(X_$(CFG_BUILD_TRIPLE))
174173
$(Q)rm -f $(PHB)/rustdoc$(X_$(CFG_BUILD_TRIPLE))
175-
$(Q)rm -f $(PHB)/rustdoc_ng$(X_$(CFG_BUILD_TRIPLE))
176174
$(Q)rm -f $(PHL)/$(CFG_RUSTLLVM_$(CFG_BUILD_TRIPLE))
177175
$(Q)rm -f $(PHL)/$(CFG_RUNTIME_$(CFG_BUILD_TRIPLE))
178176
$(Q)for i in \
@@ -182,7 +180,6 @@ uninstall:
182180
$(call HOST_LIB_FROM_HL_GLOB,$(LIBSYNTAX_GLOB_$(CFG_BUILD_TRIPLE))) \
183181
$(call HOST_LIB_FROM_HL_GLOB,$(LIBRUSTPKG_GLOB_$(CFG_BUILD_TRIPLE))) \
184182
$(call HOST_LIB_FROM_HL_GLOB,$(LIBRUSTDOC_GLOB_$(CFG_BUILD_TRIPLE))) \
185-
$(call HOST_LIB_FROM_HL_GLOB,$(LIBRUSTDOCNG_GLOB_$(CFG_BUILD_TRIPLE))) \
186183
$(call HOST_LIB_FROM_HL_GLOB,$(LIBRUSTI_GLOB_$(CFG_BUILD_TRIPLE))) \
187184
$(call HOST_LIB_FROM_HL_GLOB,$(LIBRUST_GLOB_$(CFG_BUILD_TRIPLE))) \
188185
; \

branches/auto/mk/tests.mk

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
# The names of crates that must be tested
1717
TEST_TARGET_CRATES = std extra
18-
TEST_HOST_CRATES = rust rusti rustpkg rustc rustdoc rustdocng syntax
18+
TEST_HOST_CRATES = rust rusti rustpkg rustc rustdoc syntax
1919
TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
2020

2121
# Markdown files under doc/ that should have their code extracted and run
@@ -393,14 +393,6 @@ $(3)/stage$(1)/test/rustdoctest-$(2)$$(X_$(2)): \
393393
@$$(call E, compile_and_link: $$@)
394394
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
395395

396-
$(3)/stage$(1)/test/rustdocngtest-$(2)$$(X_$(2)): \
397-
$$(RUSTDOCNG_LIB) $$(RUSTDOCNG_INPUTS) \
398-
$$(SREQ$(1)_T_$(2)_H_$(3)) \
399-
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBSYNTAX_$(2)) \
400-
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
401-
@$$(call E, compile_and_link: $$@)
402-
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
403-
404396
endef
405397

406398
$(foreach host,$(CFG_HOST_TRIPLES), \

branches/auto/mk/tools.mk

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ RUSTDOC_INPUTS := $(wildcard $(S)src/librustdoc/*.rs)
2525

2626
# rustdoc_ng, the next generation documentation tool
2727

28-
RUSTDOCNG_LIB := $(S)src/rustdoc_ng/rustdoc_ng.rs
28+
RUSTDOCNG_LIB := $(S)src/rustdoc_ng/lib.rs
2929
RUSTDOCNG_INPUTS := $(wildcard $(S)src/rustdoc_ng/*.rs)
3030

3131
# Rusti, the JIT REPL
@@ -208,14 +208,6 @@ $$(HLIB$(2)_H_$(4))/$(CFG_LIBRUSTDOCNG_$(4)): \
208208
$$(wildcard $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBRUSTDOCNG_DSYM_GLOB_$(4))) \
209209
$$(HLIB$(2)_H_$(4))
210210

211-
$$(HBIN$(2)_H_$(4))/rustdoc_ng$$(X_$(4)): \
212-
$$(TBIN$(1)_T_$(4)_H_$(3))/rustdoc_ng$$(X_$(4)) \
213-
$$(HLIB$(2)_H_$(4))/$(CFG_LIBRUSTDOCNG_$(4)) \
214-
$$(HSREQ$(2)_H_$(4)) \
215-
| $$(HBIN$(2)_H_$(4))/
216-
@$$(call E, cp: $$@)
217-
$$(Q)cp $$< $$@
218-
219211
$$(HLIB$(2)_H_$(4))/$(CFG_LIBRUSTI_$(4)): \
220212
$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBRUSTI_$(4)) \
221213
$$(HLIB$(2)_H_$(4))/$(CFG_LIBRUSTC_$(4)) \

branches/auto/src/driver/driver.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,4 @@ extern mod this(name = "rust");
2323
#[cfg(rustc)]
2424
extern mod this(name = "rustc");
2525

26-
#[cfg(rustdoc_ng)]
27-
extern mod this(name = "rustdoc_ng");
28-
2926
fn main() { this::main() }

0 commit comments

Comments
 (0)