Skip to content
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

Remove CARGO_HOME from docker env var #262

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11476,6 +11476,24 @@ const TARGET_ALIASES = {
aarch64: 'aarch64-pc-windows-msvc'
}
};
const ALLOWED_ENV_PREFIXES = [
'CARGO_',
'RUST',
'MATURIN_',
'PYO3_',
'TARGET_',
'CMAKE_',
'CC',
'CFLAGS',
'CXX',
'CXXFLAGS',
'CPPFLAGS',
'LDFLAGS',
'ACTIONS_',
'SCCACHE_',
'JEMALLOC_'
];
const FORBIDDEN_ENVS = ['CARGO_HOME'];
function hasZigSupport(target) {
if (target.startsWith('s390x')) {
return false;
Expand Down Expand Up @@ -11832,21 +11850,7 @@ async function dockerBuild(container, maturinRelease, args) {
core.endGroup();
const dockerEnvs = [];
for (const env of Object.keys(process.env)) {
if (env.startsWith('CARGO_') ||
env.startsWith('RUST') ||
env.startsWith('MATURIN_') ||
env.startsWith('PYO3_') ||
env.startsWith('TARGET_') ||
env.startsWith('CMAKE_') ||
env.startsWith('CC') ||
env.startsWith('CFLAGS') ||
env.startsWith('CXX') ||
env.startsWith('CXXFLAGS') ||
env.startsWith('CPPFLAGS') ||
env.startsWith('LDFLAGS') ||
env.startsWith('ACTIONS_') ||
env.startsWith('SCCACHE_') ||
env.startsWith('JEMALLOC_')) {
if (isDockerEnv(env)) {
dockerEnvs.push('-e');
dockerEnvs.push(env);
}
Expand Down Expand Up @@ -11908,6 +11912,16 @@ async function dockerBuild(container, maturinRelease, args) {
}
return exitCode;
}
function isDockerEnv(env) {
if (!FORBIDDEN_ENVS.includes(env)) {
for (const prefix of ALLOWED_ENV_PREFIXES) {
if (env.startsWith(prefix)) {
return true;
}
}
}
return false;
}
async function installRustTarget(target, toolchain) {
if (!target || target.length === 0) {
return;
Expand Down
60 changes: 42 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,32 @@ const TARGET_ALIASES: Record<string, Record<string, string>> = {
}
}

/**
* Allowed prefixes for env variables to pass to docker
*/
const ALLOWED_ENV_PREFIXES: string[] = [
'CARGO_',
'RUST',
'MATURIN_',
'PYO3_',
'TARGET_',
'CMAKE_',
'CC',
'CFLAGS',
'CXX',
'CXXFLAGS',
'CPPFLAGS',
'LDFLAGS',
'ACTIONS_',
'SCCACHE_',
'JEMALLOC_'
]

/**
* Forbidden env variables that should not be passed to docker
*/
const FORBIDDEN_ENVS: string[] = ['CARGO_HOME']

/**
* Does the target has Zig cross compilation support
*/
Expand Down Expand Up @@ -617,24 +643,7 @@ async function dockerBuild(

const dockerEnvs = []
for (const env of Object.keys(process.env)) {
if (
env.startsWith('CARGO_') ||
env.startsWith('RUST') ||
env.startsWith('MATURIN_') ||
env.startsWith('PYO3_') ||
env.startsWith('TARGET_') ||
env.startsWith('CMAKE_') ||
env.startsWith('CC') ||
env.startsWith('CFLAGS') ||
env.startsWith('CXX') ||
env.startsWith('CXXFLAGS') ||
env.startsWith('CPPFLAGS') ||
env.startsWith('LDFLAGS') ||
env.startsWith('ACTIONS_') ||
env.startsWith('SCCACHE_') ||
// for example JEMALLOC_SYS_WITH_LG_PAGE=16
env.startsWith('JEMALLOC_')
) {
if (isDockerEnv(env)) {
dockerEnvs.push('-e')
dockerEnvs.push(env)
}
Expand Down Expand Up @@ -706,6 +715,21 @@ async function dockerBuild(
return exitCode
}

/**
* Check if an environment variable should be passed to docker
* @param env The name of the environment variable
*/
function isDockerEnv(env: string): boolean {
if (!FORBIDDEN_ENVS.includes(env)) {
for (const prefix of ALLOWED_ENV_PREFIXES) {
if (env.startsWith(prefix)) {
return true
}
}
}
return false
}

/**
* Install Rust target using rustup
* @param target Rust target name
Expand Down
Loading