Установите ZED без корня на машине LinuxLinux

Ответить Пред. темаСлед. тема
Anonymous
 Установите ZED без корня на машине Linux

Сообщение Anonymous »

Установите zed без корня на машине ...
это в основном работает ... Я получаю исполняемый файл ZED ... но не запускается ... любые идеи.#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::chdir;
use Cwd 'abs_path';
use File::Spec;

# compact helpers
my $B = "$ENV{HOME}/rustme";
sub mk { system("mkdir -p @_")==0 or die "mkdir @_ failed\n" }
sub download {
my ($name,$file,$url,$tag)=@_;
unless (-e $tag) {
print "Downloading $name...\n";
system("curl -L --connect-timeout 30 --max-time 600 -o $file '$url'")==0
or die "Download failed\n";
system("touch $tag");
} else {
print "$name already downloaded.\n";
}
}
sub extract {
my ($name,$file,$dir,$tag,$opts)=@_;
unless (-e $tag) {
print "Creating $name directory...\n" if $opts->{strip};
print "Extracting $name...\n";
mk("rm -rf $dir") if -d $dir;
mk($dir);
system($opts->{cmd}->())==0 or die "$name extraction failed\n";
system("touch $tag");
} else {
print "$name already extracted.\n";
}
}

# Zed configuration
my $zed_v = "v0.166.2"; # latest stable
my $zed_zip = "$B/zed-$zed_v.tar.gz";
my $zed_dtag = "$B/.zed_downloaded";
my $zed_utag = "$B/.zed_unzipped";

# Rust configuration
my $rv = "1.85.0";
my $tr = "x86_64-unknown-linux-gnu";
my $rust_install = "$B/rust-install";

# X11 installation dir
my $x11_install_dir = "$B/x11-deps";

# —————— Original helper subs ——————
sub get_nproc {
my $n = `nproc 2>/dev/null` || 1;
chomp $n;
return $n || 1;
}

sub setup_x11_build_environment {
my $current = $ENV{PKG_CONFIG_PATH} || "";
$ENV{PKG_CONFIG_PATH} = "$x11_install_dir/lib/pkgconfig:$x11_install_dir/share/pkgconfig:$x11_install_dir/lib/x86_64-linux-gnu/pkgconfig";
$ENV{PKG_CONFIG_PATH} .= ":$current" if $current;
$ENV{PKG_CONFIG} = "$x11_install_dir/bin/pkgconf";
$current = $ENV{CPPFLAGS} || "";
$ENV{CPPFLAGS} = "-I$x11_install_dir/include $current";
$current = $ENV{LDFLAGS} || "";
$ENV{LDFLAGS} = "-L$x11_install_dir/lib -L$x11_install_dir/lib/x86_64-linux-gnu $current";
$current = $ENV{LD_LIBRARY_PATH} || "";
$ENV{LD_LIBRARY_PATH} = "$x11_install_dir/lib:$x11_install_dir/lib/x86_64-linux-gnu:$current";
$current = $ENV{PATH} || "";
$ENV{PATH} = "$x11_install_dir/bin:$ENV{HOME}/.local/bin:$current";
$current = $ENV{ACLOCAL_PATH} || "";
$ENV{ACLOCAL_PATH} = "$x11_install_dir/share/aclocal:$current";
}

sub install_meson_ninja_via_pip {
my $tag = "$B/.meson_ninja_installed";
unless (-e $tag) {
print "Installing meson and ninja via pip3...\n";
my $pip = system("which pip3 > /dev/null 2>&1")==0 ? "pip3" : system("which pip > /dev/null 2>&1")==0 ? "pip" : die "ERROR: pip not found\n";
print "Installing meson and ninja using $pip...\n";
system("$pip install --user meson ninja")==0 or die "Failed to install meson/ninja\n";
my $home = $ENV{HOME};
(-x "$home/.local/bin/meson" && -x "$home/.local/bin/ninja")
or die "meson/ninja installation verification failed\n";
system("touch $tag");
print "✓ meson and ninja installed successfully\n";
} else {
print "meson and ninja already installed via pip.\n";
}
}

sub download_x11_dependency {
my ($dep) = @_;
my ($name,$ver,$url,$opt) = @$dep{qw/name version url tar_opts/};
my $ext = $opt eq 'J'? 'tar.xz': $opt eq 'j'? 'tar.bz2': 'tar.gz';
my $file = "$B/${name}-$ver.$ext";
my $done = "$file.done";
if (-e $done) {
print "$name $ver already downloaded.\n";
return $file;
}
print "Downloading $name $ver...\n";
system("curl -L --connect-timeout 30 --max-time 600 -o $file '$url'")==0
or die "Failed to download $name\n";
-s $file or die "Downloaded file $file is empty\n";
system("touch $done");
return $file;
}

sub build_x11_dependency {
my ($dep,$tar) = @_;
my $n = $dep->{name};
my $v = $dep->{version};
my $opt = $dep->{tar_opts};
my $tag = "$B/.built-$n-$v";
return print "$n $v already built, skipping.\n" if -e $tag;
print "Building $n $v...\n";
setup_x11_build_environment();
my $tmp = "/tmp/$n-$v";
system("rm -rf $tmp; mkdir -p $tmp")==0 or die "Cannot prepare $tmp\n";
print "Extracting $tar to /tmp...\n";
system("tar -x$opt" . "f $tar -C /tmp")==0 or die "Extract $n failed\n";
my $d = -d "$tmp/$n-$v"? "$tmp/$n-$v" : -d "$tmp/libxkbcommon-$v" && $n eq 'libxkbcommon'? "$tmp/libxkbcommon-$v" : die "Cannot find extract dir for $n\n";
print "Building in $d\n";
chdir $d or die $!;
# special-cases
if ($n eq 'libxkbcommon' || $n eq 'wayland' || $n eq 'wayland-protocols' || $n eq 'xkeyboard-config') {
system("mkdir -p build")==0 or die;
chdir "build";
my $meson = "$ENV{HOME}/.local/bin/meson";
-x $meson or die "meson missing\n";
my $opts = $n eq 'libxkbcommon'
? "--prefix=$x11_install_dir -Denable-docs=false -Denable-wayland=false -Denable-x11=true -Dxkb-config-root=$x11_install_dir/share/X11/xkb"
: $n eq 'wayland' ? "--prefix=$x11_install_dir -Ddocumentation=false -Dtests=false"
: "";
system("$meson setup .. $opts")==0 or die "$n meson setup failed\n";
my $ninja = "$ENV{HOME}/.local/bin/ninja";
-x $ninja or die "ninja missing\n";
system("$ninja && $ninja install")==0 or die "$n build failed\n";
}
elsif ($n eq 'openssl') {
system("./Configure linux-x86_64 --prefix=$x11_install_dir --openssldir=$x11_install_dir/ssl --libdir=lib shared")==0 or die;
my $p = get_nproc();
system("make -j$p && make install")==0 or die;
# fix lib64→lib
if (-d "$x11_install_dir/lib64") {
for my $lib (qw(libssl.so libcrypto.so libssl.a libcrypto.a)) {
system("cp $x11_install_dir/lib64/$lib $x11_install_dir/lib/")==0 or warn;
}
}
# pkgconfig
mk("$x11_install_dir/lib/pkgconfig");
for my $pc (qw(openssl libssl libcrypto)) {
open my $fh,'>',$x11_install_dir."/lib/pkgconfig/$pc.pc" or die;
print $fh p r i n t & q u o t ; B u i l d i n g X 1 1 d e p e n d e n c i e s f r o m s o u r c e . . . \ n T h i s w i l l t a k e a w h i l e b u t o n l y n e e d s t o b e d o n e o n c e . \ n & q u o t ; ; < b r / > m k ( $ x 1 1 _ i n s t a l l _ d i r , & q u o t ; $ x 1 1 _ i n s t a l l _ d i r / b i n & q u o t ; ) ; < b r / > i n s t a l l _ m e s o n _ n i n j a _ v i a _ p i p ( ) ; < b r / > m y @ d e p s = ( < b r / > { n a m e = & g t ; & q u o t ; p k g c o n f & q u o t ; , v e r s i o n = & g t ; ' 1 . 9 . 5 ' , u r l = & g t ; ' h t t p s : / / d i s t f i l e s . a r i a d n e . s p a c e / p k g c o n f / p k g c o n f - 1 . 9 . 5 . t a r . x z ' , t a r _ o p t s = & g t ; ' J ' } , < b r / > { n a m e = & g t ; & q uot;m4",version=>'1.4.19',url=>'https://ftp.gnu.org/gnu/m4/m4-1.4.19.ta ... r_opts=>'J'},
{name=>"flex",version=>'2.6.4',url=>'https://github.com/westes/flex/releases ... r_opts=>'z'},
{name=>"bison",version=>'3.8.2',url=>'https://ftp.gnu.org/gnu/bison/bison-3.8 ... r_opts=>'J'},
{name=>"libxml2",version=>'2.11.5',url=>'https://download.gnome.org/sources/libx ... r_opts=>'J'},
{name=>"expat",version=>'2.5.0',url=>'https://github.com/libexpat/libexpat/re ... r_opts=>'J'},
{name=>"libffi",version=>'3.4.4',url=>'https://github.com/libffi/libffi/releas ... r_opts=>'z'},
{name=>"wayland",version=>'1.22.0',url=>'https://gitlab.freedesktop.org/wayland/ ... r_opts=>'J'},
{name=>"wayland-protocols",version=>'1.32',url=>'https://gitlab.freedesktop.org/wayland/ ... r_opts=>'J'},
{name=>"zlib",version=>'1.3.1',url=>'https://github.com/madler/zlib/releases ... r_opts=>'J'},
{name=>"openssl",version=>'3.0.15',url=>'https://www.openssl.org/source/openssl- ... r_opts=>'z'},
{name=>"cmake",version=>'3.28.3',url=>'https://github.com/Kitware/CMake/releas ... r_opts=>'z'},
{name=>"util-macros",version=>'1.20.0',url=>'https://www.x.org/pub/individual/util/u ... r_opts=>'J'},
{name=>"xorgproto",version=>'2023.2',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"libXau",version=>'1.0.11',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"libXdmcp",version=>'1.1.4',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"xcb-proto",version=>'1.15.2',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"libxcb",version=>'1.15',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"xtrans",version=>'1.5.0',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"libX11",version=>'1.8.7',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"libXext",version=>'1.3.5',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"libXrender",version=>'0.9.11',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"libXrandr",version=>'1.5.3',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"libXfixes",version=>'6.0.1',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"libXcursor",version=>'1.2.1',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"libXi",version=>'1.8.1',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"libXinerama",version=>'1.1.5',url=>'https://xorg.freedesktop.org/releases/i ... r_opts=>'J'},
{name=>"xkeyboard-config",version=>'2.40',url=>'https://www.x.org/pub/individual/data/x ... r_opts=>'J'},
{name=>"libxkbcommon",version=>'1.9.2',url=>'https://github.com/lfs-book/libxkbcommo ... r_opts=>'z'},
{name=>"alsa-lib",version=>'1.2.11',url=>'https://www.alsa-project.org/files/pub/ ... r_opts=>'j'},
);
for my $d (@deps) {
my $t = download_x11_dependency($d);
build_x11_dependency($d,$t);
}
system("touch $tag");
print "X11 dependencies built successfully.\n";
} else {
print "X11 dependencies already built.\n";
}
}

# —————— Main flow ——————
print "Creating rustme directory at: $B\n";
mk($B);

# Zed download & extract
download("Zed source code", $zed_zip,
"https://github.com/zed-industries/zed/a ... d_v.tar.gz",
$zed_dtag);
extract("Zed", $zed_zip, "$B/zed-$zed_v", $zed_utag,
{ strip=>1, cmd=>sub { "tar -xzf $zed_zip --strip-components=1 -C $B/zed-$zed_v" } });

# Rust download & extract
download("Rust toolchain", "$B/rust-$rv-$tr.tar.xz",
"https://static.rust-lang.org/dist/rust-$rv-$tr.tar.xz",
"$B/.rust_downloaded");
extract("Rust toolchain", "$B/rust-$rv-$tr.tar.xz", $B, "$B/.rust_extracted",
{ strip=>0, cmd=>sub { "tar --exclude='*/rust-docs/*' -xvf $B/rust-$rv-$tr.tar.xz" } });

download("Rust std library", "$B/rust-std-$rv-$tr.tar.xz",
"https://static.rust-lang.org/dist/rust- ... $tr.tar.xz",
"$B/.rust_std_downloaded");
extract("Rust std library", "$B/rust-std-$rv-$tr.tar.xz", $B, "$B/.rust_std_extracted",
{ strip=>0, cmd=>sub { "tar --exclude='*/rust-docs/*' -xvf $B/rust-std-$rv-$tr.tar.xz" } });

# Install Rust components
my $rit = "$B/.rust_installed";
unless (-e $rit) {
print "Installing Rust components...\n";
mk($rust_install);
chdir "$B/rust-$rv-$tr" or die;
print "Installing Rust toolchain...\n";
system("./install.sh --prefix=$rust_install --without=rust-docs")==0 or die;
chdir "$B/rust-std-$rv-$tr" or die;
print "Installing Rust std library...\n";
system("./install.sh --prefix=$rust_install")==0 or die;
system("touch $rit");
} else {
print "Rust components already installed.\n";
}

# Check basic tools
print "Checking for basic build tools...\n";
for my $t (["GCC","gcc"],["make","make"],["python3","python3"]) {
my ($n,$c)=@$t;
system("which $c > /dev/null 2>&1")==0
or die "ERROR: $n is not available. Please install build-essential.\n";
print "✓ $n found: ", qx($c --version | head -1);
}

# Build X11 deps
build_x11_dependencies();

# Setup environment and build Zed
my $abs_rust = abs_path($rust_install);
my $abs_x11 = abs_path($x11_install_dir);
my $cargo = File::Spec->catfile($abs_rust,"bin","cargo");
my $rustc = File::Spec->catfile($abs_rust,"bin","rustc");

$ENV{PATH} = "$abs_rust/bin:$abs_x11/bin:$ENV{HOME}/.local/bin:$ENV{PATH}";
$ENV{RUSTUP_HOME} = $abs_rust;
$ENV{CARGO_HOME} = $abs_rust;
setup_x11_build_environment();
$ENV{CC} = "gcc";
$ENV{CXX} = "g++";

print "Using Rust installation at: $abs_rust\n";
print "Using X11 libraries at: $abs_x11\n";
print "Using GCC as the C/C++ compiler\n";

print "Checking Rust installation...\n";
system("$rustc --version")==0 or die "Rust compiler not working\n";
system("$cargo --version")==0 or die "Cargo not working\n";

print "Checking cmake installation...\n";
system("$abs_x11/bin/cmake --version")==0 or die "cmake not working\n";

print "Checking meson and ninja installation...\n";
my $home = $ENV{HOME};
(-x "$home/.local/bin/meson" && -x "$home/.local/bin/ninja")
or die "ERROR: meson or ninja not found\n";
print "✓ meson found: ", qx($home/.local/bin/meson --version);
print "✓ ninja found: ", qx($home/.local/bin/ninja --version);

# Verify libxkbcommon
print "Checking libxkbcommon installation...\n";
my $libok=0;
for my $sub ("","/x86_64-linux-gnu") {
if (-f "$abs_x11/lib$sub/libxkbcommon.so" && -f "$abs_x11/lib$sub/libxkbcommon-x11.so") {
$libok=1;
print "✓ libxkbcommon found in lib$sub/\n";
if ($sub) {
for my $f (qw(libxkbcommon.so libxkbcommon-x11.so libxkbcommon.so.0 libxkbcommon-x11.so.0)) {
system("ln -sf x86_64-linux-gnu/$f $abs_x11/lib/$f")==0 or warn;
}
print "✔️ symlinks created for compatibility\n";
}
last;
}
}
unless ($libok) {
print "ERROR: libxkbcommon not found. Contents:\n";
system("ls -la $abs_x11/lib | grep xkb");
die "libxkbcommon build verification failed\n";
}

# Cargo config for Zed
print "Setting up Cargo configuration for Zed...\n";
my $cdir = "$B/zed-$zed_v/.cargo";
mk($cdir);
open my $cf,'>',$cdir."/config.toml" or die $!;
print $cf

Подробнее здесь: https://stackoverflow.com/questions/796 ... ux-machine
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Linux»