On 12/15/2013 07:52 AM, Liigo Zhuang wrote:
Rust compiler compiles "crates", rustpkg manages "packages".

When develope a library for rust, I write these code in lib.rs
<http://lib.rs>:
```
#[pkgid = "whoami"];
#[crate_type = "lib"];
…………
```
Note, I set its "package" id, and set its "crate" type, and it is
compiled to an .so library. Now please tell me, what "it" is? A package?
A crate? or just a library? If it's a package, why I set its crate type?
If it's a crate, why I set its package id? Confusing.

I agree that 'pkgid' is a really unfortunate name that stems from the confusion of whether or not a package is allowed to contain multiple crates. I think it should, but it feels like I'm in a minority. 'pkgid' is used to generate the crate output name, at least for libraries, (i.e. lib<name>-<hash>-<version>.so). Frankly, I liked the old link metadata idea better where you specified the Author, Version and output name separately, and it was not conflated with the rustpkg idea. I believe the movement to #[pkgid] was driven by the desire for external tools to be able to compute the hash (e.g. see http://metajack.im/2013/12/12/building-rust-code--using-make/)... but I think that's a mistake. I really don't think this is a solution:

RUST_CRATE_PKGID = $(shell sed -ne 's/^#[ *pkgid *= *"(.*)" *];$$/\1/p' $(firstword $(1))) RUST_CRATE_HASH = $(shell printf $(strip $(1)) | shasum -a 256 | sed -ne 's/^(.{8}).*$$/\1/p')
_rust_crate_pkgid = $$(call RUST_CRATE_PKGID, $$(_rust_crate_lib))
_rust_crate_hash = $$(call RUST_CRATE_HASH, $$(_rust_crate_pkgid))

I'd rather just do:

RUST_CRATE_HASH = $(shell rustc --get-crate-hash $1)
_rust_crate_hash = $$(call RUST_CRATE_HASH, $$(_rust_crate_lib))

Personally, I'd remove the notion of a package id from the language, and leave it entirely up to the external package management tool to deal with.

That'd mean the removal of the unfortunate `extern mod foo = "pkgid";` syntax which conflates crates and packages (it could be replaced with `#[pkgid="pkgid"] extern mod foo;` if source annotation of external dependencies is really desired. It'd have to have different semantics in order not to repeat the confusion.).


And when use it ("whoami"), I must write the code:
```
extern mod whoami;
```
Now was it transmuted to a "module"?? If it's a module, why I haven't
set its module id and module type? If it's not a module, why not use
`extern package whoami` or  `extern crate whoami` here? Full of confusion.

Can you please tell me WHAT it really is? Thank you.

For what it is worth, "extern mod" is slated to be changed to be "crate", I think: https://github.com/mozilla/rust/issues/9880 .

-SL
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to