1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 09:50:43 +00:00

Remove Bazel (#469)

due to https://github.com/v2fly/v2ray-core/pull/468
This commit is contained in:
Loyalsoldier 2020-11-30 20:48:17 +08:00 committed by GitHub
parent 3342afbada
commit 7de5bca056
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 0 additions and 716 deletions

View File

@ -1 +0,0 @@
workspace(name = "v2ray_core")

View File

@ -1,5 +0,0 @@
filegroup(
name = "rules",
srcs = glob(["*.bzl"]),
visibility = ["//visibility:public"],
)

View File

@ -1,68 +0,0 @@
def _go_command(ctx):
output = ctx.attr.output
if ctx.attr.os == "windows":
output = output + ".exe"
output_file = ctx.actions.declare_file(ctx.attr.os + "/" + ctx.attr.arch + "/" + ctx.attr.ver + "/" + output)
pkg = ctx.attr.pkg
ld_flags = "-s -w -buildid="
if ctx.attr.ld:
ld_flags = ld_flags + " " + ctx.attr.ld
options = [
"go",
"build",
"-trimpath",
"-o", output_file.path,
"-ldflags", "'%s'" % ld_flags,
"-tags", "'%s'" % ctx.attr.gotags,
pkg,
]
command = " ".join(options)
envs = [
"CGO_ENABLED=0",
"GOOS="+ctx.attr.os,
"GOARCH="+ctx.attr.arch,
"GO111MODULE=on",
"GOCACHE=${TMPDIR}/gocache"
]
if ctx.attr.mips: # https://github.com/golang/go/issues/27260
envs+=["GOMIPS="+ctx.attr.mips]
envs+=["GOMIPS64="+ctx.attr.mips]
envs+=["GOMIPSLE="+ctx.attr.mips]
envs+=["GOMIPS64LE="+ctx.attr.mips]
if ctx.attr.arm:
envs+=["GOARM="+ctx.attr.arm]
switchToPwd="cd ${SPWD} && "
command = switchToPwd + " ".join(envs) + " " + command
ctx.actions.run_shell(
outputs = [output_file],
command = command,
use_default_shell_env = True,
)
runfiles = ctx.runfiles(files = [output_file])
return [DefaultInfo(executable = output_file, runfiles = runfiles)]
foreign_go_binary = rule(
_go_command,
attrs = {
'pkg': attr.string(),
'output': attr.string(),
'os': attr.string(mandatory=True),
'arch': attr.string(mandatory=True),
'ver': attr.string(mandatory=True),
'mips': attr.string(),
'arm': attr.string(),
'ld': attr.string(),
'gotags': attr.string(),
},
executable = True,
)

View File

@ -1,25 +0,0 @@
SUPPORTED_MATRIX = [
("windows", "amd64", "0"),
("windows", "386", "0"),
("windows", "arm", "7"),
("darwin", "amd64", "0"),
("linux", "amd64", "0"),
("linux", "386", "0"),
("linux", "arm64", "0"),
("linux", "arm", "7"),
("linux", "arm", "6"),
("linux", "arm", "5"),
("linux", "mips64", "0"),
("linux", "mips", "0"),
("linux", "mips64le", "0"),
("linux", "mipsle", "0"),
("linux", "ppc64", "0"),
("linux", "ppc64le", "0"),
("linux", "riscv64", "0"),
("linux", "s390x", "0"),
("freebsd", "amd64", "0"),
("freebsd", "386", "0"),
("openbsd", "amd64", "0"),
("openbsd", "386", "0"),
("dragonfly", "amd64", "0"),
]

View File

@ -1,161 +0,0 @@
# Copied from google/nomulus project as we don't want to import the whole repository.
ZIPPER = "@bazel_tools//tools/zip:zipper"
def long_path(ctx, file_):
"""Constructs canonical runfile path relative to TEST_SRCDIR.
Args:
ctx: A Skylark rule context.
file_: A File object that should appear in the runfiles for the test.
Returns:
A string path relative to TEST_SRCDIR suitable for use in tests and
testing infrastructure.
"""
if file_.short_path.startswith("../"):
return file_.short_path[3:]
if file_.owner and file_.owner.workspace_root:
return file_.owner.workspace_root + "/" + file_.short_path
return ctx.workspace_name + "/" + file_.short_path
def collect_runfiles(targets):
"""Aggregates runfiles from targets.
Args:
targets: A list of Bazel targets.
Returns:
A list of Bazel files.
"""
data = depset()
for target in targets:
if hasattr(target, "runfiles"):
data += target.runfiles.files
continue
if hasattr(target, "data_runfiles"):
data += target.data_runfiles.files
if hasattr(target, "default_runfiles"):
data += target.default_runfiles.files
return data
def _get_runfiles(target, attribute):
runfiles = getattr(target, attribute, None)
if runfiles:
return runfiles.files
return []
def _zip_file(ctx):
"""Implementation of zip_file() rule."""
for s, d in ctx.attr.mappings.items():
if (s.startswith("/") or s.endswith("/") or
d.startswith("/") or d.endswith("/")):
fail("mappings should not begin or end with slash")
srcs = depset(transitive = [depset(ctx.files.srcs),depset(ctx.files.data),depset(collect_runfiles(ctx.attr.data))])
mapped = _map_sources(ctx, srcs, ctx.attr.mappings)
cmd = [
"#!/bin/sh",
"set -e",
'repo="$(pwd)"',
'zipper="${repo}/%s"' % ctx.file._zipper.path,
'archive="${repo}/%s"' % ctx.outputs.out.path,
'tmp="$(mktemp -d "${TMPDIR:-/tmp}/zip_file.XXXXXXXXXX")"',
'cd "${tmp}"',
]
cmd += [
'"${zipper}" x "${repo}/%s"' % dep.zip_file.path
for dep in ctx.attr.deps
]
cmd += ["rm %s" % filename for filename in ctx.attr.exclude]
cmd += [
'mkdir -p "${tmp}/%s"' % zip_path
for zip_path in depset(
[
zip_path[:zip_path.rindex("/")]
for _, zip_path in mapped
if "/" in zip_path
],
).to_list()
]
cmd += [
'ln -sf "${repo}/%s" "${tmp}/%s"' % (path, zip_path)
for path, zip_path in mapped
]
cmd += [
("find . | sed 1d | cut -c 3- | LC_ALL=C sort" +
' | xargs "${zipper}" cC "${archive}"'),
'cd "${repo}"',
'rm -rf "${tmp}"',
]
script = ctx.actions.declare_file("%s/%s.sh" % (ctx.bin_dir, ctx.label.name))
ctx.actions.write(output = script, content = "\n".join(cmd), is_executable = True)
inputs = [ctx.file._zipper]
inputs += [dep.zip_file for dep in ctx.attr.deps]
inputs += list(srcs.to_list())
ctx.actions.run(
inputs = inputs,
outputs = [ctx.outputs.out],
executable = script,
mnemonic = "zip",
progress_message = "Creating zip with %d inputs %s" % (
len(inputs),
ctx.label,
),
)
return struct(files = depset([ctx.outputs.out]), zip_file = ctx.outputs.out)
def _map_sources(ctx, srcs, mappings):
"""Calculates paths in zip file for srcs."""
# order mappings with more path components first
mappings = sorted([
(-len(source.split("/")), source, dest)
for source, dest in mappings.items()
])
# get rid of the integer part of tuple used for sorting
mappings = [(source, dest) for _, source, dest in mappings]
mappings_indexes = range(len(mappings))
used = {i: False for i in mappings_indexes}
mapped = []
for file_ in srcs.to_list():
run_path = long_path(ctx, file_)
zip_path = None
for i in mappings_indexes:
source = mappings[i][0]
dest = mappings[i][1]
if not source:
if dest:
zip_path = dest + "/" + run_path
else:
zip_path = run_path
elif source == run_path:
if dest:
zip_path = dest
else:
zip_path = run_path
elif run_path.startswith(source + "/"):
if dest:
zip_path = dest + run_path[len(source):]
else:
zip_path = run_path[len(source) + 1:]
else:
continue
used[i] = True
break
if not zip_path:
fail("no mapping matched: " + run_path)
mapped += [(file_.path, zip_path)]
for i in mappings_indexes:
if not used[i]:
fail('superfluous mapping: "%s" -> "%s"' % mappings[i])
return mapped
pkg_zip = rule(
implementation = _zip_file,
attrs = {
"out": attr.output(mandatory = True),
"srcs": attr.label_list(allow_files = True),
"data": attr.label_list(allow_files = True),
"deps": attr.label_list(providers = ["zip_file"]),
"exclude": attr.string_list(),
"mappings": attr.string_dict(),
"_zipper": attr.label(default = Label(ZIPPER), allow_single_file = True),
},
)

View File

@ -1,6 +0,0 @@
load("//infra/bazel:matrix.bzl", "SUPPORTED_MATRIX")
load("//infra/control/main:targets.bzl", "gen_targets")
package(default_visibility=["//visibility:public"])
gen_targets(SUPPORTED_MATRIX)

View File

@ -1,45 +0,0 @@
load("//infra/bazel:build.bzl", "foreign_go_binary")
def gen_targets(matrix):
pkg = "./infra/control/main"
output = "v2ctl"
for (os, arch, ver) in matrix:
if arch in ["arm"]:
bin_name = "v2ctl_" + os + "_" + arch + "_" + ver
foreign_go_binary(
name = bin_name,
pkg = pkg,
output = output,
os = os,
arch = arch,
ver = ver,
arm = ver,
gotags = "confonly",
)
else:
bin_name = "v2ctl_" + os + "_" + arch
foreign_go_binary(
name = bin_name,
pkg = pkg,
output = output,
os = os,
arch = arch,
ver = ver,
gotags = "confonly",
)
if arch in ["mips", "mipsle"]:
bin_name = "v2ctl_" + os + "_" + arch + "_softfloat"
foreign_go_binary(
name = bin_name,
pkg = pkg,
output = output + "_softfloat",
os = os,
arch = arch,
ver = ver,
mips = "softfloat",
gotags = "confonly",
)

View File

@ -1,6 +0,0 @@
load("//infra/bazel:matrix.bzl", "SUPPORTED_MATRIX")
load("//main:targets.bzl", "gen_targets")
package(default_visibility=["//visibility:public"])
gen_targets(SUPPORTED_MATRIX)

View File

@ -1,67 +0,0 @@
load("//infra/bazel:build.bzl", "foreign_go_binary")
def gen_targets(matrix):
pkg = "./main"
output = "v2ray"
for (os, arch, ver) in matrix:
if arch in ["arm"]:
bin_name = "v2ray_" + os + "_" + arch + "_" + ver
foreign_go_binary(
name = bin_name,
pkg = pkg,
output = output,
os = os,
arch = arch,
ver = ver,
arm = ver,
)
if os in ["windows"]:
bin_name = "v2ray_" + os + "_" + arch + "_" + ver + "_nowindow"
foreign_go_binary(
name = bin_name,
pkg = pkg,
output = "w" + output,
os = os,
arch = arch,
ver = ver,
arm = ver,
ld = "-H windowsgui",
)
else:
bin_name = "v2ray_" + os + "_" + arch
foreign_go_binary(
name = bin_name,
pkg = pkg,
output = output,
os = os,
arch = arch,
ver = ver,
)
if os in ["windows"]:
bin_name = "v2ray_" + os + "_" + arch + "_nowindow"
foreign_go_binary(
name = bin_name,
pkg = pkg,
output = "w" + output,
os = os,
arch = arch,
ver = ver,
ld = "-H windowsgui",
)
if arch in ["mips", "mipsle"]:
bin_name = "v2ray_" + os + "_" + arch + "_softfloat"
foreign_go_binary(
name = bin_name,
pkg = pkg,
output = output + "_softfloat",
os = os,
arch = arch,
ver = ver,
mips = "softfloat",
)

View File

@ -1,326 +0,0 @@
package(default_visibility = ["//visibility:public"])
load("//infra/bazel:zip.bzl", "pkg_zip")
load("//release:mapping.bzl", "gen_mappings")
filegroup(
name = "config_json",
srcs = [
"config/config.json",
"config/vpoint_socks_vmess.json",
"config/vpoint_vmess_freedom.json",
],
)
filegroup(
name = "systemd",
srcs = [
"config/systemd/system/v2ray.service",
"config/systemd/system/v2ray@.service",
],
)
filegroup(
name = "geodata",
srcs = [
"config/geoip.dat",
"config/geosite.dat",
],
)
pkg_zip(
name = "v2ray_darwin_amd64_package",
srcs = [
":config_json",
":geodata",
"//infra/control/main:v2ctl_darwin_amd64",
"//main:v2ray_darwin_amd64",
],
out = "v2ray-macos-64.zip",
mappings = gen_mappings("darwin", "amd64", "0"),
)
pkg_zip(
name = "v2ray_windows_amd64_package",
srcs = [
":config_json",
":geodata",
"//infra/control/main:v2ctl_windows_amd64",
"//main:v2ray_windows_amd64",
"//main:v2ray_windows_amd64_nowindow",
],
out = "v2ray-windows-64.zip",
mappings = gen_mappings("windows", "amd64", "0"),
)
pkg_zip(
name = "v2ray_windows_x86_package",
srcs = [
":config_json",
":geodata",
"//infra/control/main:v2ctl_windows_386",
"//main:v2ray_windows_386",
"//main:v2ray_windows_386_nowindow",
],
out = "v2ray-windows-32.zip",
mappings = gen_mappings("windows", "386", "0"),
)
pkg_zip(
name = "v2ray_windows_armv7_package",
srcs = [
":config_json",
":geodata",
"//infra/control/main:v2ctl_windows_arm_7",
"//main:v2ray_windows_arm_7",
"//main:v2ray_windows_arm_7_nowindow",
],
out = "v2ray-windows-arm32-v7a.zip",
mappings = gen_mappings("windows", "arm", "7"),
)
pkg_zip(
name = "v2ray_freebsd_amd64_package",
srcs = [
":config_json",
":geodata",
"//infra/control/main:v2ctl_freebsd_amd64",
"//main:v2ray_freebsd_amd64",
],
out = "v2ray-freebsd-64.zip",
mappings = gen_mappings("freebsd", "amd64", "0"),
)
pkg_zip(
name = "v2ray_freebsd_x86_package",
srcs = [
":config_json",
":geodata",
"//infra/control/main:v2ctl_freebsd_386",
"//main:v2ray_freebsd_386",
],
out = "v2ray-freebsd-32.zip",
mappings = gen_mappings("freebsd", "386", "0"),
)
pkg_zip(
name = "v2ray_openbsd_amd64_package",
srcs = [
":config_json",
":geodata",
"//infra/control/main:v2ctl_openbsd_amd64",
"//main:v2ray_openbsd_amd64",
],
out = "v2ray-openbsd-64.zip",
mappings = gen_mappings("openbsd", "amd64", "0"),
)
pkg_zip(
name = "v2ray_openbsd_x86_package",
srcs = [
":config_json",
":geodata",
"//infra/control/main:v2ctl_openbsd_386",
"//main:v2ray_openbsd_386",
],
out = "v2ray-openbsd-32.zip",
mappings = gen_mappings("openbsd", "386", "0"),
)
pkg_zip(
name = "v2ray_dragonfly_amd64_package",
srcs = [
":config_json",
":geodata",
"//infra/control/main:v2ctl_dragonfly_amd64",
"//main:v2ray_dragonfly_amd64",
],
out = "v2ray-dragonfly-64.zip",
mappings = gen_mappings("dragonfly", "amd64", "0"),
)
pkg_zip(
name = "v2ray_linux_amd64_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_amd64",
"//main:v2ray_linux_amd64",
],
out = "v2ray-linux-64.zip",
mappings = gen_mappings("linux", "amd64", "0"),
)
pkg_zip(
name = "v2ray_linux_x86_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_386",
"//main:v2ray_linux_386",
],
out = "v2ray-linux-32.zip",
mappings = gen_mappings("linux", "386", "0"),
)
pkg_zip(
name = "v2ray_linux_arm64_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_arm64",
"//main:v2ray_linux_arm64",
],
out = "v2ray-linux-arm64-v8a.zip",
mappings = gen_mappings("linux", "arm64", "0"),
)
pkg_zip(
name = "v2ray_linux_armv7_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_arm_7",
"//main:v2ray_linux_arm_7",
],
out = "v2ray-linux-arm32-v7a.zip",
mappings = gen_mappings("linux", "arm", "7"),
)
pkg_zip(
name = "v2ray_linux_armv6_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_arm_6",
"//main:v2ray_linux_arm_6",
],
out = "v2ray-linux-arm32-v6.zip",
mappings = gen_mappings("linux", "arm", "6"),
)
pkg_zip(
name = "v2ray_linux_armv5_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_arm_5",
"//main:v2ray_linux_arm_5",
],
out = "v2ray-linux-arm32-v5.zip",
mappings = gen_mappings("linux", "arm", "5"),
)
pkg_zip(
name = "v2ray_linux_mips32_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_mips",
"//infra/control/main:v2ctl_linux_mips_softfloat",
"//main:v2ray_linux_mips",
"//main:v2ray_linux_mips_softfloat",
],
out = "v2ray-linux-mips32.zip",
mappings = gen_mappings("linux", "mips", "0"),
)
pkg_zip(
name = "v2ray_linux_mips32le_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_mipsle",
"//infra/control/main:v2ctl_linux_mipsle_softfloat",
"//main:v2ray_linux_mipsle",
"//main:v2ray_linux_mipsle_softfloat",
],
out = "v2ray-linux-mips32le.zip",
mappings = gen_mappings("linux", "mipsle", "0"),
)
pkg_zip(
name = "v2ray_linux_mips64_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_mips64",
"//main:v2ray_linux_mips64",
],
out = "v2ray-linux-mips64.zip",
mappings = gen_mappings("linux", "mips64", "0"),
)
pkg_zip(
name = "v2ray_linux_mips64le_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_mips64le",
"//main:v2ray_linux_mips64le",
],
out = "v2ray-linux-mips64le.zip",
mappings = gen_mappings("linux", "mips64le", "0"),
)
pkg_zip(
name = "v2ray_linux_riscv64_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_riscv64",
"//main:v2ray_linux_riscv64",
],
out = "v2ray-linux-riscv64.zip",
mappings = gen_mappings("linux", "riscv64", "0"),
)
pkg_zip(
name = "v2ray_linux_s390x_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_s390x",
"//main:v2ray_linux_s390x",
],
out = "v2ray-linux-s390x.zip",
mappings = gen_mappings("linux", "s390x", "0"),
)
pkg_zip(
name = "v2ray_linux_ppc64_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_ppc64",
"//main:v2ray_linux_ppc64",
],
out = "v2ray-linux-ppc64.zip",
mappings = gen_mappings("linux", "ppc64", "0"),
)
pkg_zip(
name = "v2ray_linux_ppc64le_package",
srcs = [
":config_json",
":geodata",
":systemd",
"//infra/control/main:v2ctl_linux_ppc64le",
"//main:v2ray_linux_ppc64le",
],
out = "v2ray-linux-ppc64le.zip",
mappings = gen_mappings("linux", "ppc64le", "0"),
)

View File

@ -1,6 +0,0 @@
def gen_mappings(os, arch, ver):
return {
"v2ray_core/release/config": "",
"v2ray_core/main/" + os + "/" + arch + "/" + ver: "",
"v2ray_core/infra/control/main/" + os + "/" + arch + "/" + ver : "",
}