Skip to content

book should mention crates.io in FFI chapter #29762

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

Closed
durka opened this issue Nov 11, 2015 · 8 comments
Closed

book should mention crates.io in FFI chapter #29762

durka opened this issue Nov 11, 2015 · 8 comments

Comments

@durka
Copy link
Contributor

durka commented Nov 11, 2015

If you blindly copy the example code from the FFI chapter you get the "libc is unstable" warning.

@durka
Copy link
Contributor Author

durka commented Nov 11, 2015

Ugh... so the examples have a hidden #![feature(libc)] line, so you'll see that if you click through to the playpen. I see why it's done that way (so the examples are runnable) but it seems bad, pedagogically. Thoughts?

@steveklabnik
Copy link
Member

The issue is, normally, you want to copy the code exactly, and put libc in your cargo.toml. That's why I hid it.

@durka
Copy link
Contributor Author

durka commented Nov 11, 2015

Yeah, that makes sense. So maybe just a mention at the beginning about putting libc in Cargo.toml. And maaaybe another sentence about how if you click the examples some extra lines get inserted to make it compile in the playpen? (About half of them don't compile anyway since they refer to nonexistent libraries, though this could be fixed with even more hidden lines containing #[cfg] trickery.)

@steveklabnik
Copy link
Member

👍

@durka
Copy link
Contributor Author

durka commented Nov 11, 2015

Fun bash ...thing to pull code blocks out of a Markdown file and try compiling them:

for block in $(grep -n '```' src/doc/trpl/ffi.md | paste -s -d ':\n' - | grep 'rust\|no_run')
do
    from=$(echo $block | cut -d: -f1);
    to=$(echo $block | cut -d: -f3);
    f=$(mktemp /tmp/doctest.XXX);
    head -$((to - 1)) src/doc/trpl/ffi.md | tail -$(($to - $from - 1)) | sed 's/^# //' >$f;
    mr ru nightly rustc $f >/dev/null 2>&1 && rm doctest;
    echo $from $?;
    rm $f;
done

@steveklabnik
Copy link
Member

rustdoc --test path/to/markdown will do that already :)

@durka
Copy link
Contributor Author

durka commented Nov 11, 2015

Oh, how about that :)

@durka
Copy link
Contributor Author

durka commented Nov 11, 2015

Does that not try linking? 'Cause it says everything passes but my bash script disagrees.

steveklabnik added a commit to steveklabnik/rust that referenced this issue Nov 12, 2015

Verified

This commit was signed with the committer’s verified signature.
weswigham Wesley Wigham
…bnik

Crates.io is now mentioned right at the top to try and head off the `#![feature(libc)]` error.

In addition, the examples now all compile and run in the playpen. I also tweaked spacing in some of them.

Fixes rust-lang#29762.

r? @steveklabnik
steveklabnik added a commit to steveklabnik/rust that referenced this issue Nov 17, 2015

Verified

This commit was signed with the committer’s verified signature.
weswigham Wesley Wigham
steveklabnik added a commit to steveklabnik/rust that referenced this issue Nov 17, 2015
steveklabnik added a commit to steveklabnik/rust that referenced this issue Nov 17, 2015
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

No branches or pull requests

3 participants