A cargo subcommand to fetch the $OUT_DIR environment variable from build scripts

Overview

cargo-outdir crates.io

A cargo subcommand to fetch the $OUT_DIR variable from build scripts.

This is extremely useful to inspect the output of automatically generated code, like bindgen or parol.

This can be seen as an extension to cargo metadata, except it requires that cargo check succeeds.

If cargo check succeeds, then this command succeeds too (and give the same output).

Due to recent changes in cargo check, this will not invalidate cached outputs, so the build scripts wont be re-run unless they need to :)

It is effectively a workaround to rust-lang/cargo#7546

Examples

$ cargo out

Assuming your current crate is named current-crate, this wil output something like:

current-crate /Users/techcable/git/current-crate/target/debug/build/current-crate-82e5bb1cb82b68a7/out

Alternatively, to omit the name you can use --no-names. This is useful in shell scripts as $(cargo out --no-names)

This command works with any crate name (as long as it has a build.rs file).

$ cargo out syn indexmap

syn /Users/techcable/git/current-crate/target/debug/build/syn-2bbc24a01fc81726/out
indexmap /Users/techcable/git/current-crate/target/debug/build/indexmap-376e9f234cf30ee8/out

These are output in the order specified on the command line, seperated by newlines.

If the package doesn't have an out dir, the output will be "" exactly and the exit code will be 2.

You might want to consider json output as well.

$ cargo out --json --all

{
    "syn": "/Users/techcable/git/current-crate/target/debug/build/syn-2bbc24a01fc81726/out",
    "indexmap": "/Users/techcable/git/current-crate/target/debug/build/indexmap-376e9f234cf30ee8/out",
    "libc:0.1.12": null,
    "libc:0.2.109": "/Users/techcable/git/current-crate/target/debug/build/libc-1c95e0902b980b08/out",
    // other_crates here
}

If packages don't have an $OUT_DIR (because they don't have a build script), then the value for the specified key will be null.

This can be used along with jq for easy processing in scripts :)

If multiple packages have the same name, then version will be added. More precicely, the json keys will be the minimal cargo pkgid needed to disambiguate them. This is actually somewhat difficult to do :)

How it works

This runs cargo check --message-format=json and extracts only the nessicarry information.

Historically this has been an issue for IDEs, both intellij-rust and rust-analsyer have struggled to support this.

Do to recent compiler changes, this will always output the proper $OUT_DIR variables for all packages that have one.

However recent changes to cargo check have made this possible. It sill :)

You might also like...
TypeRust - simple Rust playground where you can build or run your Rust code and share it with others

Rust playground Welcome to TypeRust! This is a simple Rust playground where you can build or run your Rust code and share it with others. There are a

Automated license checking for rust. cargo lichking is a Cargo subcommand that checks licensing information for dependencies.

cargo-lichking Automated license checking for rust. cargo lichking is a Cargo subcommand that checks licensing information for dependencies. Liches ar

cargo-lambda a Cargo subcommand to help you work with AWS Lambda

cargo-lambda cargo-lambda is a Cargo subcommand to help you work with AWS Lambda. This subcommand compiles AWS Lambda functions natively and produces

cargo-lambda is a Cargo subcommand to help you work with AWS Lambda.

cargo-lambda cargo-lambda is a Cargo subcommand to help you work with AWS Lambda. The new subcommand creates a basic Rust package from a well defined

Cargo subcommand for running cargo without dev-dependencies.

cargo-no-dev-deps Cargo subcommand for running cargo without dev-dependencies. This is an extraction of the --no-dev-deps flag of cargo-hack to be use

A cargo subcommand that extends cargo's capabilities when it comes to code generation.

cargo-px Cargo Power eXtensions Check out the announcement post to learn more about cargo-px and the problems it solves with respect to code generatio

Dead simple, memoized cargo subcommand to hoist cargo-built binaries into the current working directory, written in Rust.
Dead simple, memoized cargo subcommand to hoist cargo-built binaries into the current working directory, written in Rust.

cargo-hoist Dead simple cargo subcommand to hoist cargo-built binaries into scope. stable Install | User Docs | Crate Docs | Reference | Contributing

A tool that uses the credentials stored in 1password as an environment variable.

openv A tool that uses the credentials stored in 1password as an environment variable. Requirements 1password command-line tool Getting Started # Sign

FlatBuffers compiler (flatc) as API (with focus on transparent `.fbs` to `.rs` code-generation via Cargo build scripts integration)

FlatBuffers flatc API for Rust This crate provides a programmatical way to invoke flatc command (e.g. from build.rs) to generate Rust (or, in fact, an

Cargo subcommand to automatically create universal libraries for iOS.

cargo lipo Provides a cargo lipo subcommand which automatically creates a universal library for use with your iOS application. Maintenance Status Plea

A very simple third-party cargo subcommand to execute a custom command

cargo-x A very simple third-party cargo subcommand to execute a custom command Usage install cargo-x cargo install cargo-x or upgrade cargo install -

a cargo subcommand for counting lines of code in Rust projects
a cargo subcommand for counting lines of code in Rust projects

cargo-count Linux: A cargo subcommand for displaying line counts of source code in projects, including a niave unsafe counter for Rust source files. T

A cargo subcommand for creating GraphViz DOT files and dependency graphs
A cargo subcommand for creating GraphViz DOT files and dependency graphs

cargo-graph Linux: A cargo subcommand for building GraphViz DOT files of dependency graphs. This subcommand was originally based off and inspired by t

Cargo script subcommand

cargo-script cargo-script is a Cargo subcommand designed to let people quickly and easily run Rust "scripts" which can make use of Cargo's package eco

A cargo subcommand for checking and applying updates to installed executables

cargo-update A cargo subcommand for checking and applying updates to installed executables Documentation Manpage Installation Firstly, ensure you have

Cargo subcommand `release`: everything about releasing a rust crate.

cargo release Features Ensure you are in a good state for release, including: Right branch Up-to-date with remote Clean tree Supports workspaces using

A cargo subcommand for displaying when Rust dependencies are out of date

cargo-outdated Linux: A cargo subcommand for displaying when Rust dependencies are out of date About cargo-outdated is for displaying when dependencie

A Cargo subcommand for the client-side Web
A Cargo subcommand for the client-side Web

A cargo subcommand for the client-side Web This cargo subcommand aims to make it easy and convenient to build, develop and deploy client-side Web appl

A cargo subcommand that displays ghidra function output through the use of the rizin rz-ghidra project.

cargo-rz-ghidra A cargo subcommand that displays ghidra function output through the use of the rizin rz-ghidra project. Install cargo install --git ht

Releases(v0.1.0)
Owner
Developer | Student | Semi-retired Minecraft dev | Compiler Nerd 🤓
null
Neofetch but in Rust (rust-toml-fetch)

rtfetch Configuration Recompile each time you change the config file logo = "arch.logo" # in src/assets. info = [ "", "", "<yellow>{host_n

Paolo Bettelini 6 Jun 6, 2022
Rust development environment for MIPS on NT4

Summary This is a project which allows us to run Rust "shellcode" in a MIPS environment on NT 4.0. TL;DR Setup NT Install NT 4.0 MIPS in QEMU using th

null 19 Dec 18, 2022
Rust environment for Stellar Jump Cannon.

rs-stellar-contract-env Rust contract-environment interface and (optional) host implementation for Stellar Jump Cannon. This crate contains elements o

Stellar 24 Dec 15, 2022
Rust, cargo and QEMU setup for multi-architecture OS development.

rust-osdev-jumpstart Rust, cargo and QEMU setup for multi-architecture OS development. Goal This repo should give you a boost in starting a bare-metal

Alister Lee 27 Nov 20, 2022
A cargo plugin for showing a tree-like overview of a crate's modules.

cargo-modules Synopsis A cargo plugin for showing an overview of a crate's modules. Motivation With time, as your Rust projects grow bigger and bigger

Vincent Esche 445 Jan 3, 2023
probe-run is a custom Cargo runner that transparently runs Rust firmware on an embedded device

probe-run Runs embedded programs just like native ones probe-run is a custom Cargo runner that transparently runs Rust firmware on an embedded device.

Knurling 483 Jan 7, 2023
cargo-add command to make dependencies into dylibs

cargo add-dynamic This cargo command allows to wrap dependencies as dylibs. For why you might want this see Speeding up incremental Rust compilation w

Robert Krahn 62 Dec 27, 2022
Fegeya Elitebuild, small, powerful build system. Written in Rust.

Fegeya Elitebuild Small, powerful, work-in-progress build system. Written in Rust. Features: No functions (all are built-ins) All variables are global

Ferhat Geçdoğan 25 Nov 9, 2022
Featured Dioxus projects on how to build clean user interfaces in Rust

Example projects with Dioxus This repository holds the code for a variety of example projects built with Dioxus. Each project has information on how t

Dioxus 189 Jan 8, 2023
Build database expression type checker and vectorized runtime executor in type-safe Rust

Typed Type Exercise in Rust Build database expression type checker and vectorized runtime executor in type-safe Rust. This project is highly inspired

Andy Lok 89 Dec 27, 2022