Skip to content

users-selected environment variables to pass into the docker instance #1782

Description

@jtmoon79

Checklist

Describe your request

tl;dr allow the user to pass-in environment variables of their choosing to the docker instance

I have an unusual build.rs that looks at some environment variables to determine what to build. In my case, environment variable S4_BUILD_REGEX determines which regular expressions to build. Limiting the built regular expressions is useful in various development scenarios.

But the command env S4_BUILD_REGEX=1 cargo cross build ..., the environment variable S4_BUILD_REGEX has no effect on what is built. That is presumably because it's a project-specific environment variable that is not brought into the launched docker instance.

Checklist

  • This feature could be solved with a custom image (optional)

That would infeasible as the build environment variable S4_BUILD_REGEX changes often. Rebuilding a docker image every time would be a lot of tedious wrapper scripts. This Feature seems like an easy and useful addition to cross.

Describe why this would be a good inclusion for cross

Allows the user flexibility in builds using cross. like for example, allow the user to pass-in environment variables that effect their project's build.

Other users may want to forward some uncommon environment variables to the compiler within the docker container. This feature would make that easy and intuitive.

Design suggestion

My suggestion is a CLI option, for example call it --env, that takes values VAR=VAL.
The option --env should be allowed multiple times. The parsing code splits on the first = char.
Examples:

  • cargo cross build --env=S4_BUILD_REGEX=1,2 --env=S4_BUILD_PRINT=1 ... would pass along two environment variables with the shown values.

These arguments would be passed along to docker run as --env argument(s).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions