These are chat archives for rust-lang/rust

29th
Dec 2017
libchaos
@libchaos
Dec 29 2017 07:05
I am new to rust, it’s werid grammer frustrates me, can anyone give me some advices?
Restioson
@Restioson
Dec 29 2017 08:30
What would you like advice on?
mhsjlw
@mhsjlw
Dec 29 2017 14:04
any good guides for running rust in production
andrew bernard
@drexler
Dec 29 2017 14:08
@epage awesome :+1:
Restioson
@Restioson
Dec 29 2017 16:06
@mhsjlw guides that tell you what kind of stuff?
mhsjlw
@mhsjlw
Dec 29 2017 16:53
containerization practices, maybe deployment packagers like distillery for elixir. perhaps other attempts at production and things they learned
I tried to find some but they're quite sparse
Steve Klabnik
@steveklabnik
Dec 29 2017 18:04
since rust produces a single static binary (generally), containers aren't as big of an issue
there are some people who use docker, but i don't, personally
https://www.youtube.com/watch?v=GCsxYAxw3JQ is more about advocacy to companies than production advice exactly
but migth be of interest, possibly
Jeremy Lempereur
@o0Ignition0o
Dec 29 2017 18:40
ag_dubs <3
Hans W. Uhlig
@huhlig
Dec 29 2017 18:41
silly question, is there an easy way to specify or get the name of the generated executable from cargo?
Aleksey Kladov
@matklad
Dec 29 2017 18:45
no easy way, but you can pass --message-format=json and look for artifact messages
Hans W. Uhlig
@huhlig
Dec 29 2017 18:45
hmm
Ed Page
@epage
Dec 29 2017 18:46
Is the package name good enough? You could adapt some clap code to read from CARGO_PKG_NAME
Hans W. Uhlig
@huhlig
Dec 29 2017 18:47
I'm trying to build out a build script for a cloud foundry install
so I need to grab the executable name from somewhere
or specify a common name somehow
Ed Page
@epage
Dec 29 2017 18:48
Ok, so external to the rust code.
Hans W. Uhlig
@huhlig
Dec 29 2017 18:48
preferably without requiring code modifications
yeah
Ed Page
@epage
Dec 29 2017 18:54
If you are ok with linking against cargo, you could mirror what cargo install does and call compile_ws which gives you a Compilation which includes the paths to all of the binaries
Hans W. Uhlig
@huhlig
Dec 29 2017 18:56
not a bad idea... actually I wonder if submitting an upstream patch for something like cargo output to print out expected results would work
Ed Page
@epage
Dec 29 2017 18:57
Why make it upstream when you can make custom cargo subcommands? It'll probably be less stress doing it that way because then you don't need to determine what works for the whole ecosystem before putting it in.
Hans W. Uhlig
@huhlig
Dec 29 2017 18:57
fair point
darn, one doesn't already exist
Aleksey Kladov
@matklad
Dec 29 2017 19:08
No need to link-to cargo: you can run cargo metadata as a subprocess and get all info as json
Hans W. Uhlig
@huhlig
Dec 29 2017 19:08
hmm
lemmie look
interesting
well darn
it doesn't seem to specify output artifacts
just dependencies
Aleksey Kladov
@matklad
Dec 29 2017 19:15
Yeah, the exact location of output artifact depends on the particular compilation
like, binary foo may end up in target/debug or target/release or perhaps elsewhere, if we add custom profiles.
Hans W. Uhlig
@huhlig
Dec 29 2017 19:16
yeah
Aleksey Kladov
@matklad
Dec 29 2017 19:16
That's why message-format JSON requires that you execute the actual build.
Hans W. Uhlig
@huhlig
Dec 29 2017 19:16
makes sense
Aleksey Kladov
@matklad
Dec 29 2017 19:16
metadata gives you the names of the artifacts (name field in target), but it does not give you paths.
Hans W. Uhlig
@huhlig
Dec 29 2017 19:17
it didn't provide me the name
"root":"ibm-cloud-rust-web-template 0.0.1 (path+file:///C:/Users/huhlig/Projects/rust/ibm-cloud-rust-web-template)"
it gave me that
Aleksey Kladov
@matklad
Dec 29 2017 19:18
Look at the targets section
There'll be stuff like {"kind":["bin"],"crate_types":["bin"],"name":"gen","src_path":"/home/matklad/projects/libsyntax2/src/bin/gen.rs"}
Hans W. Uhlig
@huhlig
Dec 29 2017 19:18
err
there is no targets
packages, workspace_members, resolve
Aleksey Kladov
@matklad
Dec 29 2017 19:19
And each package should have a targets field?
Hans W. Uhlig
@huhlig
Dec 29 2017 19:19
oh... well that's not helpful at all
I want the package im compiling...
I don't know which package is mine
why is there not a top level targets for the crate being compiled
Aleksey Kladov
@matklad
Dec 29 2017 19:20
That's a tricky question :) If you are compiling a workspace, you compile a bunch of packages, and all of them are yours
Hans W. Uhlig
@huhlig
Dec 29 2017 19:20
sigh
Aleksey Kladov
@matklad
Dec 29 2017 19:20
So, workspace_members is your packages.
Hans W. Uhlig
@huhlig
Dec 29 2017 19:22
which gives me ibm-cloud-rust-web-template 0.0.1 (path+file:///C:/Users/huhlig/Projects/rust/ibm-cloud-rust-web-template)
Aleksey Kladov
@matklad
Dec 29 2017 19:22
So, yeah, what package I am compiling again depends on how exactly you execute cargo. You may invoke cargo build -p, or cargo build --all
Hans W. Uhlig
@huhlig
Dec 29 2017 19:22
so I guess I could grab that and split it out
ok, fair enough
I must say.. cargo is a bitch to automate in a generic fashion
Aleksey Kladov
@matklad
Dec 29 2017 19:22
so I guess I could grab that and split it out
Not really
Each package contains an id field
so you should just find the pacakge with matching id
(the whole name-version-path thing is an "opaque" id)
Hans W. Uhlig
@huhlig
Dec 29 2017 19:23
ok, since this workspace only has 1 member the id is 0?
Aleksey Kladov
@matklad
Dec 29 2017 19:24
Btw, if you are using Rust for you thing, there's cargo-metadata crate which can help you
No, id is not numeric
ibm-cloud-rust-web-template 0.0.1 (path+file:///C:/Users/huhlig/Projects/rust/ibm-cloud-rust-web-template) <- this is the id
Hans W. Uhlig
@huhlig
Dec 29 2017 19:24
I am trying to build a cloud foundry build pack for deploying rust webapps to IBM Cloud
and doing so in an appropriately simple manner is challenging
Aleksey Kladov
@matklad
Dec 29 2017 19:25
And in what language is this "build pack" written in?
Yeah, Cargo has some non-trivial aspects to it.
Hans W. Uhlig
@huhlig
Dec 29 2017 19:25
so the compile stage can be bash or ruby
and the release step is a small script which basically has to print out a yaml file that contains a command to run
Aleksey Kladov
@matklad
Dec 29 2017 19:26
Hm, no, I unfortunately don't know about read parsers for cargo-metadata for ruby
Hans W. Uhlig
@huhlig
Dec 29 2017 19:26
yeah, and certainly none for bash
Aleksey Kladov
@matklad
Dec 29 2017 19:27
It may be the case that we need to add --output flag to Cargo, to make such stuff easier?
Hans W. Uhlig
@huhlig
Dec 29 2017 19:27
That's what I was thinking earlier
Aleksey Kladov
@matklad
Dec 29 2017 19:28
Like, cargo metadata and --message-format=json are actually awesome, because they give you very detailed information. But they are absolutely impossible to use from a bash script.
this is the current buildpack
each of these 4 scripts is run detect, supply, finalize, and release
supply sets up the build environment
finalize compiles your code
and release basically specifies the command to run inside the container
I tried doing cargo run --release as my command except after compilation the compiler isn't included in the container for space reasons
This would be much much easier in a docker container but I'm trying to make it work in both systems
I would like to get IBM to adopt and support rust and im doing my damnedist to make it happen
Ed Page
@epage
Dec 29 2017 19:32
Thanks!
Hans W. Uhlig
@huhlig
Dec 29 2017 19:34
Heh, I havent succeeded yet
Aleksey Kladov
@matklad
Dec 29 2017 19:52
@huhlig filed rust-lang/cargo#4875 :)
Hans W. Uhlig
@huhlig
Dec 29 2017 19:53
Thanks!
Hans W. Uhlig
@huhlig
Dec 29 2017 21:03
WooHoo!
I got it to work in the hackiest way possible
I do not feel good about myself