@@ -16,9 +16,6 @@ const CACHE_PREFIX = "setup-zig-global-cache-";
1616// See: https://github.com/marler8997/anyzig?tab=readme-ov-file#mach-versions-and-download-mirror
1717const MACH_ZIG_VERSION_REGEX = / \. \s * m a c h _ z i g _ v e r s i o n \s * = \s * " ( .* ?) " / ;
1818const MINIMUM_ZIG_VERSION_REGEX = / \. \s * m i n i m u m _ z i g _ v e r s i o n \s * = \s * " ( .* ?) " / ;
19- // This is tied quite precisely to the output of `zig env`. It's just a temporary workaround until
20- // I get around to implementing a ZON parser here.
21- const ZIG_ENV_CACHE_DIR_REGEX = / ^ \s * \. g l o b a l _ c a c h e _ d i r = " ( .* ) " , $ / m;
2219
2320let _cached_version = null ;
2421async function getVersion ( ) {
@@ -203,50 +200,11 @@ async function getCachePrefix() {
203200 const job_name = github . context . job . replaceAll ( / [ ^ \w ] / g, "_" ) ;
204201 const user_key = core . getInput ( 'cache-key' ) ;
205202
206- return `setup-zig-cache-${ job_name } -${ tarball_name } -${ user_key } -` ;
203+ return `setup-zig-cache-v2- ${ job_name } -${ tarball_name } -${ user_key } -` ;
207204}
208205
209- async function getZigCachePath ( ) {
210- const env_zon = ( await exec . getExecOutput ( 'zig' , [ 'env' ] ) ) . stdout ;
211- if ( env_zon [ 0 ] !== '.' ) {
212- // JSON (legacy)
213- return JSON . parse ( env_zon ) [ 'global_cache_dir' ] ;
214- }
215- const match = ZIG_ENV_CACHE_DIR_REGEX . exec ( env_zon ) ;
216- if ( ! match ) throw new Error ( "Failed to parse cache directory from 'zig env' output" ) ;
217- return parseZigString ( match [ 1 ] ) ;
218- }
219- function parseZigString ( raw ) {
220- // This function is neither complete (Unicode codepoint literals), nor correct (byte-escapes
221- // aren't really compatible with JS "strings"). It's just a temporary best-effort implementation
222- // which can hopefully handle any real-world directory path we encounter.
223- let result = "" ;
224- let i = 0 ;
225- while ( i < raw . length ) {
226- if ( raw [ i ] != '\\' ) {
227- result += raw [ i ] ;
228- i += 1 ;
229- continue ;
230- }
231- i += 2 ;
232- switch ( raw [ i - 1 ] ) {
233- case 'n' : result += '\n' ; break ;
234- case 'r' : result += '\r' ; break ;
235- case '\\' : result += '\\' ; break ;
236- case 't' : result += '\t' ; break ;
237- case '\'' : result += '\'' ; break ;
238- case '"' : result += '"' ; break ;
239- case 'x' : {
240- const byte_val = parseInt ( raw . slice ( i , i + 2 ) , 16 ) ;
241- result += String . fromCharCode ( byte_val ) ;
242- i += 2 ;
243- break ;
244- }
245- case 'u' : throw new Error ( "unsupported Unicode codepoint literal in string" ) ;
246- default : throw new Error ( "invalid escape code in string" ) ;
247- }
248- }
249- return result ;
206+ function getZigCachePath ( ) {
207+ return path . join ( process . env [ 'GITHUB_WORKSPACE' ] ?? process . cwd ( ) , '.zig-cache' ) ;
250208}
251209
252210module . exports = {
0 commit comments