From d5ee60b4a1e94d1020c8d8b4ced43812cafa4dfe Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 29 Jun 2021 13:05:43 +0300 Subject: [PATCH] v.builder: use a github repo for ~/.vmodules/linuxroot/ folder, to ease its updating --- vlib/v/builder/cc.v | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index e670274818..328954ef1e 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -752,6 +752,23 @@ fn (mut v Builder) cc() { // } } +fn (mut b Builder) ensure_linuxroot_exists(sysroot string) { + crossrepo_url := 'https://github.com/spytheman/vlinuxroot' + sysroot_git_config_path := os.join_path(sysroot, '.git', 'config') + if os.is_dir(sysroot) && !os.exists(sysroot_git_config_path) { + // remove existing obsolete unarchived .zip file content + os.rmdir_all(sysroot) or {} + } + if !os.is_dir(sysroot) { + println('Downloading files for Linux cross compilation (~22MB) ...') + os.system('git clone $crossrepo_url $sysroot') + if !os.exists(sysroot_git_config_path) { + verror('Failed to clone `$crossrepo_url` to `$sysroot`') + } + os.chmod(os.join_path(sysroot, 'ld.lld'), 0o755) + } +} + fn (mut b Builder) cc_linux_cross() { b.setup_ccompiler_options(b.pref.ccompiler) b.build_thirdparty_obj_files() @@ -761,19 +778,7 @@ fn (mut b Builder) cc_linux_cross() { os.mkdir(parent_dir) or { panic(err) } } sysroot := os.join_path(os.vmodules_dir(), 'linuxroot') - if !os.is_dir(sysroot) { - println('Downloading files for Linux cross compilation (~18 MB)...') - zip_url := 'https://github.com/vlang/v/releases/download/0.1.27/linuxroot.zip' - zip_file := sysroot + '.zip' - os.system('curl -L -o $zip_file $zip_url') - if !os.exists(zip_file) { - verror('Failed to download `$zip_url` as $zip_file') - } - os.system('tar -C $parent_dir -xf $zip_file') - if !os.is_dir(sysroot) { - verror('Failed to unzip $zip_file to $parent_dir') - } - } + b.ensure_linuxroot_exists(sysroot) obj_file := b.out_name_c + '.o' cflags := b.get_os_cflags() defines, others, libs := cflags.defines_others_libs()