-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalienfile
91 lines (83 loc) · 2.44 KB
/
alienfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use alienfile;
use Path::Tiny qw( path );
use File::Which qw( which );
plugin 'Probe::CommandLine' => (
command => 'rustc',
args => [ '--version' ],
match => qr/^rustc ([0-9\.]+)/,
version => qr/^rustc ([0-9\.]+)/,
);
plugin 'Probe::CommandLine' => (
command => 'cargo',
args => [ '--version' ],
match => qr/^cargo [0-9\.]+/,
secondary => 1,
);
sys {
gather sub {
my ($build) = @_;
if( which('rustup') ) {
# assume that rustup was used
_gather_rustup_prop($build);
}
};
};
sub _gather_rustup_prop {
my ($build) = @_;
$build->runtime_prop->{'_using_rustup'} = 1;
$build->runtime_prop->{'rustup_home'} = (`rustup show` =~ qr/^rustup home:\s+(.*)$/m )[0];
}
share {
my $rustup;
if( $^O ne 'MSWin32' ) {
$rustup = {
url => 'https://static.rust-lang.org/rustup/rustup-init.sh',
exe => [ qw(sh ./rustup-init.sh) ],
}
} else {
$rustup = {
url => 'https://static.rust-lang.org/rustup/dist/i686-pc-windows-gnu/rustup-init.exe',
exe => [ qw(.\\rustup-init.exe) ],
};
}
start_url $rustup->{url};
plugin 'Download';
plugin 'Extract::File';
build [
sub {
my ($build) = @_;
$ENV{CARGO_HOME} = $build->install_prop->{prefix};
$ENV{RUSTUP_HOME} = $ENV{ALIEN_RUST_RUSTUP_HOME} || path($build->install_prop->{prefix})->child('.rustup');
$build->log( "CARGO_HOME = $ENV{CARGO_HOME}");
$build->log( "RUSTUP_HOME = $ENV{RUSTUP_HOME}");
},
[ @{ $rustup->{exe} },
qw(--verbose -y),
qw(--no-modify-path),
qw(--profile default),
],
sub {
my ($build) = @_;
my $from = $build->install_prop->{prefix};
my $to = $build->runtime_prop->{prefix};
$build->log( "Changing contents of env file: $from -> $to");
my $env = path($from)->child('env');
$env->edit_utf8(sub {
s/\Q$from\E/$to/g;
}) if -f $env;
},
];
gather sub {
my ($build) = @_;
$build->runtime_prop->{'version'} = ( `rustc --version` =~ qr/^rustc ([0-9\.]+)/)[0];
_gather_rustup_prop($build);
my $rustup_home = path($build->runtime_prop->{rustup_home});
my $from_prefix = path($build->install_prop->{prefix});
my $to_prefix = path($build->runtime_prop->{prefix});
if( $from_prefix->subsumes( $rustup_home ) ) {
$build->runtime_prop->{rustup_home} = $rustup_home
->relative( $from_prefix )
->absolute( $to_prefix )->stringify;
}
};
}