Skip to content

Commit c7d5160

Browse files
committed
add automatically installing cosmocc
1 parent 8dee36f commit c7d5160

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

lib/Perl/Dist/APPerl.pm

+32-6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ my @smallmanifest = (
6565
'__perlarchlib__/Cwd.pm',
6666
'__perlarchlib__/DynaLoader.pm',
6767
'__perlarchlib__/Errno.pm',
68+
'__perlarchlib__/ErrnoRuntime.pm',
6869
'__perllib__/Exporter.pm',
6970
'__perllib__/Exporter/Heavy.pm',
7071
'__perlarchlib__/Fcntl.pm',
@@ -716,7 +717,7 @@ my %defconfig = (
716717
'small' => {
717718
desc => 'moving target: small',
718719
base => 'full',
719-
perl_onlyextensions => [qw(Cwd Fcntl File/Glob Hash/Util IO List/Util POSIX Socket attributes re)],
720+
perl_onlyextensions => [qw(Cwd ErrnoRuntime Fcntl File/Glob Hash/Util IO List/Util POSIX Socket attributes re)],
720721
MANIFEST => \@smallmanifest,
721722
'include_Perl-Dist-APPerl' => 0,
722723
dest => 'perl-small.com',
@@ -809,6 +810,26 @@ sub NewConfig {
809810
_write_json(PROJECT_FILE, $projectconfig);
810811
}
811812

813+
sub _install_cosmocc {
814+
my ($SiteConfig, $version) = @_;
815+
$version //= '3.3.6';
816+
my $cosmocc = SITE_REPO_DIR."/cosmocc";
817+
print "rm -rf $cosmocc\n";
818+
remove_tree($cosmocc);
819+
print "mkdir -p $cosmocc\n";
820+
make_path($cosmocc);
821+
print "cd $cosmocc\n";
822+
my $before = getcwd();
823+
chdir($cosmocc) or die "Failed to chdir $cosmocc";
824+
my $filename = "cosmocc-$version.zip";
825+
_command_or_die('wget', "https://cosmo.zip/pub/cosmocc/$filename");
826+
_command_or_die('unzip', $filename);
827+
chdir($before) or die "error resetting directory";
828+
$SiteConfig->{cosmocc} = $cosmocc;
829+
make_path(SITE_CONFIG_DIR);
830+
_write_json(SITE_CONFIG_FILE, $SiteConfig);
831+
}
832+
812833
sub InstallBuildDeps {
813834
my ($perlrepo, $cosmorepo, $cosmocc) = @_;
814835
my $SiteConfig = _load_json(SITE_CONFIG_FILE);
@@ -945,13 +966,16 @@ sub Set {
945966
my $itemconfig = _load_apperl_config(_load_apperl_configs()->{apperl_configs}, $cfgname);
946967
print Dumper($itemconfig);
947968
if(! exists $itemconfig->{nobuild_perl_bin}) {
948-
my $SiteConfig = _load_json(SITE_CONFIG_FILE) or die "cannot set without build deps (run apperlm install-build-deps)";
969+
my $SiteConfig = _load_json(SITE_CONFIG_FILE);
949970
if(! $itemconfig->{cosmo3}) {
971+
$SiteConfig or die "cannot set without build deps (run apperlm install-build-deps)";
950972
-d $SiteConfig->{cosmo_repo} or die $SiteConfig->{cosmo_repo} .' is not directory';
951973
print "cd ".$SiteConfig->{cosmo_repo}."\n";
952974
chdir($SiteConfig->{cosmo_repo}) or die "Failed to enter cosmo repo";
953975
_command_or_die('git', 'checkout', $itemconfig->{cosmo_id});
954976
} else {
977+
$SiteConfig //= {};
978+
exists $SiteConfig->{cosmocc} or _install_cosmocc($SiteConfig);
955979
-d $SiteConfig->{cosmocc} or die $SiteConfig->{cosmocc} . ' is not a directory';
956980
}
957981
$UserProjectConfig->{configs}{$cfgname}{perl_build_dir} //= $SiteConfig->{perl_repo} if !$itemconfig->{perl_url};
@@ -1031,10 +1055,10 @@ sub Configure {
10311055
my $perl_build_dir = $UserProjectConfig->{configs}{$CurAPPerlName}{perl_build_dir};
10321056
$perl_build_dir && -d $perl_build_dir or die "$perl_build_dir is not a directory";
10331057
my $itemconfig = _load_apperl_config($Configs->{apperl_configs}, $CurAPPerlName);
1034-
my $SiteConfig = _load_json(SITE_CONFIG_FILE) or die "cannot Configure without build deps (run apperlm install-build-deps)";
10351058
_install_perl_src_files($itemconfig, $perl_build_dir);
1036-
1059+
my $SiteConfig = _load_json(SITE_CONFIG_FILE);
10371060
if(! $itemconfig->{cosmo3}) {
1061+
$SiteConfig or die "cannot Configure without build deps (run apperlm install-build-deps)";
10381062
-d $SiteConfig->{cosmo_repo} or die $SiteConfig->{cosmo_repo} .' is not directory';
10391063
# build toolchain
10401064
_command_or_die('make', '-C', $SiteConfig->{cosmo_repo}, '-j', 'toolchain', 'MODE=', 'ARCH=x86_64');
@@ -1050,8 +1074,10 @@ sub Configure {
10501074
$ENV{COSMO_APE_LOADER} = $itemconfig->{cosmo_ape_loader};
10511075
$ENV{COSMO_REPO} = $SiteConfig->{cosmo_repo};
10521076
} else {
1053-
-d $SiteConfig->{cosmocc} or die $SiteConfig->{cosmocc} . ' is not a directory';
1054-
$ENV{COSMOCC} = $SiteConfig->{cosmocc};
1077+
$SiteConfig //= {};
1078+
exists $SiteConfig->{cosmocc} or _install_cosmocc($SiteConfig);
1079+
-d $SiteConfig->{cosmocc} or die $SiteConfig->{cosmocc} . ' is not a directory';
1080+
$ENV{COSMOCC} = $SiteConfig->{cosmocc};
10551081
}
10561082

10571083
# Finally Configure perl

0 commit comments

Comments
 (0)