Skip to content

Commit

Permalink
Remove CARGO_HOME from passed env var (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariocurr authored May 2, 2024
1 parent bf468cf commit ff524a2
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 33 deletions.
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

0 comments on commit ff524a2

Please sign in to comment.