diff --git a/dist/index.js b/dist/index.js index f532e49..7b9ac11 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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; @@ -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); } @@ -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; diff --git a/src/index.ts b/src/index.ts index c4dfd50..47ebc7c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -149,6 +149,32 @@ const TARGET_ALIASES: Record> = { } } +/** + * 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 */ @@ -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) } @@ -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