{"action":"created","issue":{"url":"https://api.github.com/repos/mesonbuild/meson/issues/2617","repository_url":"https://api.github.com/repos/mesonbuild/meson","labels_url":"https://api.github.com/repos/mesonbuild/meson/issues/2617/labels{/name}","comments_url":"https://api.github.com/repos/mesonbuild/meson/issues/2617/comments","events_url":"https://api.github.com/repos/mesonbuild/meson/issues/2617/events","html_url":"https://github.com/mesonbuild/meson/pull/2617","id":273249130,"number":2617,"title":"Cargo integration in Meson via an \"unstable-cargo\" module (try 2)","user":{"login":"nirbheek","id":75801,"avatar_url":"https://avatars0.githubusercontent.com/u/75801?v=4","gravatar_id":"","url":"https://api.github.com/users/nirbheek","html_url":"https://github.com/nirbheek","followers_url":"https://api.github.com/users/nirbheek/followers","following_url":"https://api.github.com/users/nirbheek/following{/other_user}","gists_url":"https://api.github.com/users/nirbheek/gists{/gist_id}","starred_url":"https://api.github.com/users/nirbheek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nirbheek/subscriptions","organizations_url":"https://api.github.com/users/nirbheek/orgs","repos_url":"https://api.github.com/users/nirbheek/repos","events_url":"https://api.github.com/users/nirbheek/events{/privacy}","received_events_url":"https://api.github.com/users/nirbheek/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2017-11-12T17:32:38Z","updated_at":"2018-02-27T18:27:27Z","closed_at":null,"author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/mesonbuild/meson/pulls/2617","html_url":"https://github.com/mesonbuild/meson/pull/2617","diff_url":"https://github.com/mesonbuild/meson/pull/2617.diff","patch_url":"https://github.com/mesonbuild/meson/pull/2617.patch"},"body":"This was made primarily so we can build librsvg with Meson, which now works: https://git.gnome.org/browse/librsvg/log/?h=wip/meson, and it actually required fewer hacks than I expected it to. \r\n\r\nThe integration can and should definitely be better, but I think the best way to get there is to have something that works right now and slowly improve Cargo till we have everything we need. Cargo is not going to magically grow API for giving greater control to build systems; we have to work towards it.\r\n\r\nI have been talking to @alexcrichton about the things that Meson would need to integrate better with Cargo, and he has been very receptive and encouraging of our efforts, and in the need for adding features to Cargo that allow Meson to control what it does a bit better.\r\n\r\nHere's what you can do right now:\r\n\r\n'Extract' build outputs from `Cargo.toml` files in your source tree with the `unstable-cargo` module and mostly use them like you would any other target. For example:\r\n\r\n```meson\r\ncargo = import('unstable-cargo')\r\n# Build the staticlib\r\nlibrsvg_internals = cargo.static_library('rsvg_internals', toml : 'Cargo.toml')\r\n\r\nlibrsvg = library('rsvg-' + rsvg_api_major, librsvg_sources,\r\n                  dependencies : [librsvg_deps, librsvg_internals])\r\n```\r\n\r\nYou can also specify the list of sources if you wish:\r\n\r\n```meson\r\ncargo.executable('mesonbin',\r\n                 toml : 'Cargo.toml',\r\n                 # This is optional, since ninja keeps track of dependencies on source files.\r\n                 sources : ['src/main.rs'],\r\n                 # Yes, installation works\r\n                 install : true)\r\n```\r\n\r\nThe sources list is optional because cargo will output a nice `depfile` for us and ninja can then keep track of when to rebuild the target.\r\n\r\nMeson TODO:\r\n* Cross-compilation\r\n* Cargo tests and benchmarks\r\n* cdylibs or rust-specific library types\r\n* `ninja dist` does not support vendoring crate sources yet (needed for librsvg)\r\n\r\n\r\nCargo TODO:\r\n* https://github.com/rust-lang/cargo/pull/4711\r\n* `CARGO_TARGET_DIR` should be an argument `--target-dir`\r\n* Options to set the output library/executable name (prefix/suffix); perhaps also in `Cargo.toml`\r\n* In general, the ability to more accurately control build outputs from via cargo arguments\r\n  * This is where our work comes in; something half-working is the best way to figure out what is needed to make it work well ;)\r\n* Dry-run downloading of sources by `cargo vendor` so we can ship a list of files instead of the sources themselves (cc @alexlarsson)\r\n\r\nCargo long-term TODO:\r\n* Output `rustc` invocations needed to build a crate so we can run everything ourselves\r\n* Overall, Meson should be able to output build artifacts exactly where it wants, and with the `rustc` flags that we want."},"comment":{"url":"https://api.github.com/repos/mesonbuild/meson/issues/comments/368977838","html_url":"https://github.com/mesonbuild/meson/pull/2617#issuecomment-368977838","issue_url":"https://api.github.com/repos/mesonbuild/meson/issues/2617","id":368977838,"user":{"login":"danigm","id":50350,"avatar_url":"https://avatars3.githubusercontent.com/u/50350?v=4","gravatar_id":"","url":"https://api.github.com/users/danigm","html_url":"https://github.com/danigm","followers_url":"https://api.github.com/users/danigm/followers","following_url":"https://api.github.com/users/danigm/following{/other_user}","gists_url":"https://api.github.com/users/danigm/gists{/gist_id}","starred_url":"https://api.github.com/users/danigm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danigm/subscriptions","organizations_url":"https://api.github.com/users/danigm/orgs","repos_url":"https://api.github.com/users/danigm/repos","events_url":"https://api.github.com/users/danigm/events{/privacy}","received_events_url":"https://api.github.com/users/danigm/received_events","type":"User","site_admin":false},"created_at":"2018-02-27T18:27:27Z","updated_at":"2018-02-27T18:27:27Z","author_association":"NONE","body":"That module could be great. We are building Fractal with meson with a custom script [1] and it could be great to have a native support for cargo.\r\n\r\n[1] https://gitlab.gnome.org/danigm/fractal/blob/master/meson.build"}}
{"actor":{"display_login":"danigm"}}