From 7de5bca05673c0b6e0c58e673bbc9842c4acc956 Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Mon, 30 Nov 2020 20:48:17 +0800 Subject: [PATCH] Remove Bazel (#469) due to https://github.com/v2fly/v2ray-core/pull/468 --- WORKSPACE | 1 - infra/bazel/BUILD | 5 - infra/bazel/build.bzl | 68 ------- infra/bazel/matrix.bzl | 25 --- infra/bazel/zip.bzl | 161 ---------------- infra/control/main/BUILD | 6 - infra/control/main/targets.bzl | 45 ----- main/BUILD | 6 - main/targets.bzl | 67 ------- release/BUILD | 326 --------------------------------- release/mapping.bzl | 6 - 11 files changed, 716 deletions(-) delete mode 100644 WORKSPACE delete mode 100644 infra/bazel/BUILD delete mode 100644 infra/bazel/build.bzl delete mode 100644 infra/bazel/matrix.bzl delete mode 100644 infra/bazel/zip.bzl delete mode 100644 infra/control/main/BUILD delete mode 100644 infra/control/main/targets.bzl delete mode 100644 main/BUILD delete mode 100644 main/targets.bzl delete mode 100644 release/BUILD delete mode 100644 release/mapping.bzl diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index 42b605356..000000000 --- a/WORKSPACE +++ /dev/null @@ -1 +0,0 @@ -workspace(name = "v2ray_core") diff --git a/infra/bazel/BUILD b/infra/bazel/BUILD deleted file mode 100644 index 7902ba21b..000000000 --- a/infra/bazel/BUILD +++ /dev/null @@ -1,5 +0,0 @@ -filegroup( - name = "rules", - srcs = glob(["*.bzl"]), - visibility = ["//visibility:public"], -) diff --git a/infra/bazel/build.bzl b/infra/bazel/build.bzl deleted file mode 100644 index aa107b979..000000000 --- a/infra/bazel/build.bzl +++ /dev/null @@ -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, -) diff --git a/infra/bazel/matrix.bzl b/infra/bazel/matrix.bzl deleted file mode 100644 index 3db57d5b0..000000000 --- a/infra/bazel/matrix.bzl +++ /dev/null @@ -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"), -] diff --git a/infra/bazel/zip.bzl b/infra/bazel/zip.bzl deleted file mode 100644 index 40f89b6d9..000000000 --- a/infra/bazel/zip.bzl +++ /dev/null @@ -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), - }, -) diff --git a/infra/control/main/BUILD b/infra/control/main/BUILD deleted file mode 100644 index 02ba8976c..000000000 --- a/infra/control/main/BUILD +++ /dev/null @@ -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) diff --git a/infra/control/main/targets.bzl b/infra/control/main/targets.bzl deleted file mode 100644 index b52dae664..000000000 --- a/infra/control/main/targets.bzl +++ /dev/null @@ -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", - ) diff --git a/main/BUILD b/main/BUILD deleted file mode 100644 index 98a45e1fb..000000000 --- a/main/BUILD +++ /dev/null @@ -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) diff --git a/main/targets.bzl b/main/targets.bzl deleted file mode 100644 index dcf2bee25..000000000 --- a/main/targets.bzl +++ /dev/null @@ -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", - ) diff --git a/release/BUILD b/release/BUILD deleted file mode 100644 index 24790a95f..000000000 --- a/release/BUILD +++ /dev/null @@ -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"), -) diff --git a/release/mapping.bzl b/release/mapping.bzl deleted file mode 100644 index 97a76c7b8..000000000 --- a/release/mapping.bzl +++ /dev/null @@ -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 : "", - }