Alien-Bazel

 view release on metacpan or  search on metacpan

alienfile  view on Meta::CPAN

#!/usr/bin/perl
#
# This file is part of Alien-Bazel
#
# This software is Copyright (c) 2022 by Auto-Parallel Technologies, Inc.
#
# This is free software, licensed under:
#
#   The GNU General Public License, Version 3, June 2007
#

use alienfile;

use strict;
use warnings;
our $VERSION = 0.013_000;

use Data::Dumper;
use English qw(-no_match_vars);  # for $OSNAME
use Time::HiRes qw(time);  # for performance timing

use constant DEBUG_BAZEL_BOOTSTRAP =>
    exists $ENV{ALIEN_BAZEL_DEBUG_BAZEL_BOOTSTRAP}
    ? $ENV{ALIEN_BAZEL_DEBUG_BAZEL_BOOTSTRAP}
    : 0;

use constant FROM_SOURCE =>
    exists $ENV{ALIEN_BAZEL_FROM_SOURCE}
    ? $ENV{ALIEN_BAZEL_FROM_SOURCE}
    : 0;

use lib 'lib';
use Alien::Bazel::Util;

# check if the operating system already has Bazel installed
plugin 'Probe::CommandLine' => (
    command => 'bazel',
    args    => [ '--version' ],
    match   => qr/bazel/,
    version => qr/bazel ([0-9\.]+)/,
);

# if the operating system does not have Bazel, then compile from source
share {
    requires 'Path::Tiny';
    requires 'File::Which';
    requires 'Alien::Build::Plugin::Download::GitHub', '0.10';

    my $time_start = time();
    print {*STDERR} '<<< DEBUG >>> have $time_start = ', $time_start, ' seconds', "\n";

    # START HERE, NEED ANSWER: how to handle prerequisites???
    # START HERE, NEED ANSWER: how to handle prerequisites???
    # START HERE, NEED ANSWER: how to handle prerequisites???
    my %os_arch_to_binary_release = (
        'darwin:aarch64'  => { suffix => 'darwin-arm64',       },
        'darwin:x86_64'   => { suffix => 'darwin-x86_64',      },
        'linux:aarch64'   => { suffix => 'linux-arm64',        },
        'linux:x86_64'    => { suffix => 'linux-x86_64',       },
        'MSWin32:aarch64' => { suffix => 'windows-arm64.exe',  },
        'MSWin32:x86_64'  => { suffix => 'windows-x86_64.exe', },
    );

    # must have prerequisites to compile from source
    # https://bazel.build/install/compile-source#bootstrap-bazel
    # $ sudo apt-get install build-essential openjdk-11-jdk zip unzip python2
#    requires Alien::Bash;
#    requires Alien::ZipUnzip;
#    requires 'Alien::unzip';
#    requires Alien::C++Toolchain;
#    requires Alien::JDK;  # v11
#    requires Alien::Python;  # v2 or v3

    # https://github.com/bazelbuild/bazel/releases
    # Bazel bootstrap archive is always "zip"; the "tar.gz" archives are NOT
    # bootstrap capable

    my %source_asset_info = (
        asset_name   => qr/^bazel-([0-9\.]+)-dist\.zip$/,
        asset_format => 'zip',
    );

    # from source by default
    my %asset_info = %source_asset_info;
    my $binary_release = 0;

    my $os_arch = join ":", ( $^O, meta->prop->{platform}{cpu}{arch}{name} );
    if( exists $os_arch_to_binary_release{$os_arch} && ! FROM_SOURCE ) {
        $binary_release = 1;
        my ($suffix) = @{ $os_arch_to_binary_release{$os_arch} }{qw(suffix)};
        %asset_info = (
            asset_name   => qr/^bazel-([0-9\.]+)-\Q${suffix}\E$/,



( run in 1.440 second using v1.01-cache-2.11-cpan-796a6f069b2 )