Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dependency information output like GCC to rustc #7633

Closed
omasanori opened this issue Jul 7, 2013 · 8 comments · Fixed by #10698
Closed

Implement dependency information output like GCC to rustc #7633

omasanori opened this issue Jul 7, 2013 · 8 comments · Fixed by #10698

Comments

@omasanori
Copy link
Contributor

Dependency information from compilers is useful to build incrementally. Without that, build process will be incorrect and/or slow.

GCC and Clang can emit such information in (a subset of) Makefile syntax. AFAIK that can be used from make (of cource) and ninja. It might be nice if rustc provides similar feature, I think.

@emberian
Copy link
Member

emberian commented Jul 7, 2013

dup of #2369 and #558, closing (complain if you disagree)

@emberian emberian closed this as completed Jul 7, 2013
@huonw
Copy link
Member

huonw commented Jul 7, 2013

I'm reopening this because I think this is worth a separate issue, since file dependencies (detecting when a recompile is needed) is different to function dependencies and incremental recompilation. I could imagine this being a subtool of rust e.g. rust deps --format=make my_crate.rs.

That said, rustpkg is designed to be a universal build tool for Rust code, so this may not be a useful/desired tool (I'll let someone else make this decision).

@huonw huonw reopened this Jul 7, 2013
@catamorphism
Copy link
Contributor

No plans to support Makefile syntax -- the focus is on rustpkg and #2369 and #558 capture what would be desirable to implement. Closing as dup.

@omasanori
Copy link
Contributor Author

I'm sorry to be unaware of duplication. I think it's nice to get rustpkg faster first, thus I'm happy with the direction.

However I doubt whether rustpkg suitable for every areas where Rust will be used. I'll use rustpkg and reopen this when I really need dependency export.

@huonw
Copy link
Member

huonw commented Jul 8, 2013

@omasanori It's actually not that hard to do (or at least, an approximation to it) as an external binary, since the parser is a normal crate (called syntax) that you can import with extern mod. e.g. the following prints a list of files that a given file imports via a mod statement. (Don't treat it is a model of good Rust code though, it's definitely not.)

extern mod syntax;
extern mod extra;
use std::hashmap::HashSet;
use syntax::{parse, visit};

fn main() {
    let filename = match std::os::args() {
        [_, name] => name,
        _ => {
            println("Expected the file path");
            fail!()
        }
    };
    let path = Path(filename);

    let parsesess = parse::new_parse_sess(None);
    let mut crate = parse::parse_crate_from_file(&path, ~[], parsesess);
    crate = syntax::ext::expand::expand_crate(parsesess, ~[], crate);

    let files = @mut HashSet::new();
    let visitor = visit::mk_vt(@visit::Visitor {
        visit_mod: |m, sp, id, tup| {
            let fname = parsesess.cm.span_to_filename(sp);
            if "<core-macros>" != fname {
                (*files).insert(fname);
            }
            visit::visit_mod(m, sp, id, tup)
        },
        .. *visit::default_visitor()
    });

    visit::visit_crate(crate, ((), visitor));

    let mut v = ~[];
    do files.consume |s| { v.push(s); }
    extra::sort::tim_sort(v);

    println(v.connect(" "));
}
~/rust/src/libextra $ ~/rust-mk extra.rs
arc.rs bitv.rs c_vec.rs comm.rs crypto/sha1.rs crypto/sha2.rs dbg.rs deque.rs dlist.rs ebml.rs extra.rs fileinput.rs flate.rs flatpipes.rs future.rs getopts.rs json.rs list.rs net_ip.rs net_tcp.rs net_url.rs num/bigint.rs num/complex.rs num/rational.rs priority_queue.rs rc.rs rl.rs rope.rs smallintmap.rs sort.rs stats.rs sync.rs tempfile.rs term.rs terminfo/parm.rs terminfo/parser/compiled.rs terminfo/terminfo.rs test.rs time.rs timer.rs treemap.rs unicode.rs uv_global_loop.rs uv_ll.rs

@omasanori
Copy link
Contributor Author

@huonw Thank you for your suggestion. I just remember what LLVM people said: make it as a set of modular library, and we will be happy. 😃

@metajack
Copy link
Contributor

I'm working on this.

@metajack metajack reopened this Nov 27, 2013
bors added a commit that referenced this issue Dec 12, 2013
This isn't super useful for libraries yet without #10593.

Fixes #7633.
@bors bors closed this as completed in 9bbef13 Dec 13, 2013
@omasanori
Copy link
Contributor Author

@metajack I really appreciate your work. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants