@@ -39,12 +39,24 @@ pub fn detect_version(ctx: *Context.CliContext, args: []const []const u8) !Smart
3939 };
4040 }
4141
42+ // Check if user has set a default version with 'zvm use'
43+ if (try find_default_version (ctx )) | default_version | {
44+ if (! is_ci_environment ()) {
45+ log .info ("No build.zig.zon found. Using default version: {s}" , .{default_version });
46+ }
47+ return SmartVersionResult {
48+ .version = default_version ,
49+ .source = .current ,
50+ .allocator = ctx .get_allocator (),
51+ };
52+ }
53+
4254 if (! is_ci_environment ()) {
4355 log .info ("No build.zig.zon found. Defaulting to master version." , .{});
4456 log .info ("Consider creating build.zig.zon with 'minimum_zig_version' field for reproducible builds." , .{});
4557 }
4658
47- // Default to master when no build.zig.zon found - this is user-friendly
59+ // Default to master when no build.zig.zon found and no default set
4860 return SmartVersionResult {
4961 .version = "master" ,
5062 .source = .current ,
@@ -260,6 +272,36 @@ pub fn is_ci_environment() bool {
260272 return false ;
261273}
262274
275+ fn find_default_version (ctx : * Context.CliContext ) ! ? []const u8 {
276+ // Look for a default version config file
277+ var config_path_buffer = try ctx .acquire_path_buffer ();
278+ defer config_path_buffer .reset ();
279+
280+ const home_dir = ctx .get_home_dir ();
281+ var stream = std .io .fixedBufferStream (config_path_buffer .slice ());
282+
283+ if (util_tool .getenv_cross_platform ("XDG_DATA_HOME" )) | xdg_data | {
284+ try stream .writer ().print ("{s}/.zm/default_version" , .{xdg_data });
285+ } else {
286+ try stream .writer ().print ("{s}/.local/share/.zm/default_version" , .{home_dir });
287+ }
288+
289+ const config_path = try config_path_buffer .set (stream .getWritten ());
290+
291+ const file = std .fs .cwd ().openFile (config_path , .{}) catch return null ;
292+ defer file .close ();
293+
294+ var version_buffer : [32 ]u8 = undefined ;
295+ const bytes_read = file .readAll (& version_buffer ) catch return null ;
296+ if (bytes_read == 0 ) return null ;
297+
298+ // Trim whitespace
299+ const content = std .mem .trim (u8 , version_buffer [0.. bytes_read ], " \t \n \r " );
300+ if (content .len == 0 ) return null ;
301+
302+ return try ctx .get_allocator ().dupe (u8 , content );
303+ }
304+
263305fn log_version_suggestion () void {
264306 log .info ("No build.zig.zon found. Consider creating one with 'minimum_zig_version' field, or specify version on command line (e.g., 'zig 0.13.0 build')" , .{});
265307}
0 commit comments