Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • bazel/ape
1 result
Show changes
Commits on Source (11)
Showing with 869 additions and 498 deletions
......@@ -28,6 +28,31 @@ test --test_output=errors
# Output as much information when a test exceeds a timeout
test --test_verbose_timeout_warnings
# These locations are cached on the CI
build --disk_cache=${CI_PROJECT_DIR}/.cache/bazel/disk
build --repository_cache=${CI_PROJECT_DIR}/.cache/bazel/repo
# Use remote cache/execution for our builds
# TODO: enable remote execution when runners support `bazel/ape`
# build --remote_executor=${CI_REMOTE_EXECUTOR}
build --remote_cache=${CI_REMOTE_CACHE}
build --remote_timeout=3600
build --remote_header=${CI_REMOTE_HEADER}
build --experimental_remote_cache_compression
build --jobs=${CI_REMOTE_JOBS}
# Upload results to the Build Event Service
build --bes_results_url=${CI_BES_RESULTS_URL}
build --bes_backend=${CI_BES_BACKEND}
# Add build metadata
build --build_metadata=REPO_URL=${CI_PROJECT_URL}
build --build_metadata=BRANCH_NAME=${CI_COMMIT_REF_NAME}
build --build_metadata=COMMIT_SHA=${CI_COMMIT_SHA}
build --build_metadata=HOST=${CI_SERVER_HOST}
build --build_metadata=ROLE=CI
build --build_metadata=USER=gitlab-ci
# Provide detailed timing information to the remote executor
build --noslim_profile
build --experimental_profile_include_target_label
build --experimental_profile_include_primary_output
# Eliminate duplicate references in the Build Event Stream
build --nolegacy_important_outputs
include:
- component: "${CI_SERVER_HOST}/ci/component/bazelisk/bazelisk@v1.0.0-beta.2"
- component: "${CI_SERVER_HOST}/ci/component/bazelisk/bazelisk@v1.0.0-beta.3"
inputs:
variables: |
CI_PROJECT_DIR
CI_PROJECT_ID
CI_REMOTE_EXECUTOR
CI_REMOTE_CACHE
CI_REMOTE_HEADER
CI_REMOTE_JOBS
CI_BES_RESULTS_URL
CI_BES_BACKEND
CI_PROJECT_URL
CI_COMMIT_REF_NAME
CI_COMMIT_SHA
CI_SERVER_HOST
default:
tags:
......
load(":binaries.bzl", "BINARIES")
load("@toolchain_utils//toolchain/symlink/target:defs.bzl", "toolchain_symlink_target")
[
alias(
toolchain_symlink_target(
name = binary,
actual = "@{}".format(binary),
target = "//ape:{}".format(binary),
visibility = ["//visibility:public"],
)
for binary in BINARIES
......
# [1.0.0-beta.3](https://git.gitlab.arm.com/bazel/ape/compare/v1.0.0-beta.2...v1.0.0-beta.3) (2024-05-01)
### Bug Fixes
- **ape.pe:** implement a C# launcher ([4f667dd](https://git.gitlab.arm.com/bazel/ape/commit/4f667dd858d683e43176d538797931f52b39f036))
- **entrypoint:** remove toolchain target ([d9d60dc](https://git.gitlab.arm.com/bazel/ape/commit/d9d60dc262dafe669e661bc48f339f77322f4a6c))
- make `@ape//:*` binaries remote execution friendly ([7ae6293](https://git.gitlab.arm.com/bazel/ape/commit/7ae62935125b5e72ccaab248bc3a73b927901403))
### Features
- add `//ape/toolchain/ape:type` ([3e73cdb](https://git.gitlab.arm.com/bazel/ape/commit/3e73cdb63c21caede525321dc8f797ec9fcc1945))
- add `ape_binary` rule ([6577cd3](https://git.gitlab.arm.com/bazel/ape/commit/6577cd36eeaf814b38a66a3c1fbd1e7ce218f1e6))
### BREAKING CHANGES
- **entrypoint:** The `toolchain_symlink_target` has been removed from `ape_entrypoint`.
This symlink target used the repository context entrypoint which is not remote execution
friendly.
The targets were aliased as `@ape//:*` which have been corrected to be remove execution
friendly. Use those targets instead.
# [1.0.0-beta.2](https://git.gitlab.arm.com/bazel/ape/compare/v1.0.0-beta.1...v1.0.0-beta.2) (2024-04-25)
### Bug Fixes
......
module(
name = "ape",
version = "1.0.0-beta.2",
version = "1.0.0-beta.3",
bazel_compatibility = [
">=7.0.0",
],
......@@ -95,6 +95,15 @@ select(
},
)
resolved = use_repo_rule("@toolchain_utils//toolchain/resolved:defs.bzl", "toolchain_resolved")
resolved(
name = "resolved-ape",
toolchain_type = "//ape/toolchain/ape:type",
)
register_toolchains("//ape/toolchain/...")
ape_entrypoint = use_repo_rule("//ape/entrypoint:defs.bzl", "ape_entrypoint")
export = use_extension("@toolchain_utils//toolchain/export:defs.bzl", "toolchain_export")
......
This diff is collapsed.
load("//:binaries.bzl", "BINARIES")
load("//ape/binary:defs.bzl", "ape_binary")
[
ape_binary(
name = binary,
target = "@cosmos-{}//:{}".format(binary, binary),
visibility = ["//:__subpackages__"],
)
for binary in BINARIES
]
alias(
name = "template",
actual = select({
"@toolchain_utils//toolchain/constraint/os:windows": ":nt.tmpl.bat",
"//conditions:default": ":posix.tmpl.sh",
}),
)
load(":rule.bzl", _binary = "binary")
visibility("//...")
ape_binary = _binary
@echo off
:: Enable Batch extensions
verify other 2>nul
setlocal EnableExtensions
if errorlevel 1 (
echo "Failed to enable extensions"
exit /b 120
)
:: Bazel substitutions
call :runfiles TARGET "{{target}}"
if errorlevel 1 exit /b %ERRORLEVEL%
call :runfiles APE "{{ape}}"
if errorlevel 1 exit /b %ERRORLEVEL%
%APE% %TARGET% %*
exit /b %ERRORLEVEL%
:runfiles - find a file in the Bazel runfiles
:: %1 - return variable
:: %2 - runfile path
setlocal
set "TARGET=%~2"
if [%RUNFILES_MANIFEST_FILE%] equ [] if exist "MANIFEST" (
set "RUNFILES_MANIFEST_FILE=MANIFEST"
)
if exist "%RUNFILES_MANIFEST_FILE%" (
for /f "tokens=1,2* usebackq" %%a in ("%RUNFILES_MANIFEST_FILE%") do (
if "_main/%TARGET%" == "%%a" (
set "RESOLVED=%%~fb"
break
)
if "%TARGET%" == "../%%a" (
set "RESOLVED=%%~fb"
break
)
)
)
if [%RESOLVED%] equ [] (
echo>&2.Failed to find runfile: %TARGET%
exit /b 2
)
endlocal & set %~1=%RESOLVED%
goto :eof
\ No newline at end of file
#! /usr/bin/env sh
# Strict shell
set -o nounset
set -o errexit
# Bazel substitutions
TARGET="{{target}}"
APE="{{ape}}"
readonly TARGET APE
# Execute!
"${APE}" "${TARGET}" "${@}"
visibility("//ape/binary/...")
DOC = """Launches an αcτµαlly pδrταblε εxεcµταblε (APE) binary with the correct launcher.
This avoids any issues with `binfmt_misc` picking up binaries under Wine or similar.
"""
ATTRS = {
"target": attr.label(
doc = "The ape binary target to launch",
allow_single_file = True,
executable = True,
cfg = "exec",
),
"_template": attr.label(
doc = "The executable template script.",
allow_single_file = True,
default = ":template",
),
}
def implementation(ctx):
ape = ctx.toolchains["//ape/toolchain/ape:type"]
executable = ctx.actions.declare_file("{}.{}".format(ctx.label.name, ctx.file._template.extension))
substitutions = ctx.actions.template_dict()
substitutions.add("{{ape}}", ape.executable.short_path)
substitutions.add("{{target}}", ctx.file.target.short_path)
ctx.actions.expand_template(
template = ctx.file._template,
output = executable,
computed_substitutions = substitutions,
is_executable = True,
)
files = depset([executable])
runfiles = ctx.runfiles([executable, ctx.file.target])
runfiles = runfiles.merge(ctx.attr.target.default_runfiles)
runfiles = runfiles.merge(ape.default.default_runfiles)
return DefaultInfo(
executable = executable,
files = files,
runfiles = runfiles,
)
ape_binary = rule(
doc = DOC,
attrs = ATTRS,
implementation = implementation,
toolchains = ["//ape/toolchain/ape:type"],
executable = True,
)
binary = ape_binary
load("@toolchain_utils//toolchain/symlink/target:defs.bzl", "toolchain_symlink_target")
exports_files({{exports}})
toolchain_symlink_target(
name = "{{binary}}",
# TODO: remove this when it is upstreamed into a new release
basename = select({
"@toolchain_utils//toolchain/constraint/os:windows": "{{binary}}.exe",
"//conditions:default": "{{binary}}",
}),
target = ":entrypoint",
visibility = ["//visibility:public"],
)
......@@ -41,7 +41,6 @@ def implementation(rctx):
rctx.template("BUILD.bazel", rctx.attr.build, {
"{{exports}}": repr(["entrypoint"]),
"{{binary}}": rctx.path(rctx.attr.binary).basename,
})
entrypoint = repository_rule(
......
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
class Entrypoint {
static int Main() {
string[] args = Environment.GetCommandLineArgs();
if (args.Length < 2) {
Console.Error.WriteLine(@"USAGE
ape PROG [ARGV1,ARGV2,...]
ape - PROG [ARGV0,ARGV1,...]");
return 1;
}
// TODO: support rewriting argument zero
if (args[1] == "-") {
Console.Error.WriteLine("`-` unsupported");
return 2;
}
// Figure out the arguments
uint index = 1;
string fileName = Path.GetFullPath(args[index]);
string arguments = "";
for (uint i = index + 1; i < args.Length; i++) {
arguments += string.Format(" \"{0}\"", args[i].Replace("\"", "\\\""));
}
// Run the binary
using(Process process = new Process()) {
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = fileName;
process.StartInfo.Arguments = arguments;
process.Start();
process.WaitForExit();
return process.ExitCode;
}
}
}
\ No newline at end of file
......@@ -13,17 +13,50 @@ ATTRS = {
allow_single_file = True,
default = ":BUILD.tmpl.bazel",
),
"false": attr.label(
doc = "The αcτµαlly pδrταblε εxεcµταblε `false` binary.",
allow_single_file = True,
executable = True,
cfg = "exec",
default = "@cosmos-false//:false",
"_cs": attr.label(
doc = "C# source code for the APE executable.",
default = ":ape.cs",
),
}
def csc(rctx):
"""Finds the C# compiler from common directories.
Args:
rctx: the repository context to perform local command execution with
Returns:
A Bazel path to the C# compiler
"""
result = rctx.execute(("cmd.exe", "/c", "@echo.%SYSTEMROOT%"))
if result.return_code != 0:
fail("Failed to find system root: {}".format(result.stderr))
root = rctx.path(result.stdout.strip())
framework = root.get_child("Microsoft.NET/Framework64")
if not framework.exists:
fail("Failed to find .NET framework: {}".format(framework))
for child in framework.readdir():
csc = child.get_child("csc.exe")
if csc.exists:
return csc
fail("Failed to find C# compiler")
def implementation(rctx):
rctx.symlink(rctx.attr.false, "ape")
compiler = csc(rctx)
ape = rctx.path("ape.exe")
source = rctx.path(rctx.attr._cs)
source = str(source).replace("/", "\\")
rctx.report_progress("Compiling C# APE")
result = rctx.execute((compiler, "/warnaserror", "/warn:4", "/nologo", "/out:{}".format(ape), "/target:exe", "/optimize", source))
if result.return_code != 0:
fail("Failed to compile C# APE: {}".format(result.stdout))
rctx.symlink("ape.exe", "ape")
rctx.template("BUILD.bazel", rctx.attr.build, {
"{{exports}}": repr(["ape"]),
......
......@@ -56,7 +56,7 @@ alias(
"dircolors": ["--version"],
"dirname": ["--version"],
"du": ["--version"],
"emacs": ["--version"],
# "emacs": ["--version"],
"emacsclient": ["--version"],
"env": ["--version"],
"expand": ["--version"],
......
load("@toolchain_utils//toolchain/symlink/target:defs.bzl", "toolchain_symlink_target")
load("@toolchain_utils//toolchain/test:defs.bzl", "toolchain_test")
toolchain_type(
name = "type",
visibility = ["//visibility:public"],
)
[
(
toolchain_symlink_target(
name = "ape-{}-{}".format(cpu, os),
target = "{}//:ape".format(target),
),
toolchain(
name = "{}-{}".format(cpu, os),
exec_compatible_with = (
"@toolchain_utils//toolchain/constraint/cpu:{}".format(cpu),
"@toolchain_utils//toolchain/constraint/os:{}".format(os),
),
toolchain = ":ape-{}-{}".format(cpu, os),
toolchain_type = ":type",
),
)
for cpu, os, target in (
("amd64", "linux", "@ape-x86_64.elf"),
("amd64", "windows", "@ape.pe"),
("amd64", "macos", "@ape-x86_64.macho"),
("amd64", "openbsd", "@ape-x86_64.elf"),
("amd64", "netbsd", "@ape-x86_64.elf"),
("amd64", "freebsd", "@ape-x86_64.elf"),
("arm64", "linux", "@ape-arm64.elf"),
("arm64", "macos", "@ape-arm64.macho"),
("arm64", "freebsd", "@ape-arm64.elf"),
)
]
alias(
name = "resolved",
actual = "@resolved-ape",
visibility = ["//visibility:public"],
)
toolchain_test(
name = "ape",
size = "small",
status = 1,
stderr = "@toolchain_utils//toolchain/test:non-empty",
stdout = "@toolchain_utils//toolchain/test:empty",
# TODO: make `ape.pe` work like an actual launcher
target_compatible_with = [
"@toolchain_utils//toolchain/constraint/os:linux",
],
toolchains = [":resolved"],
)
......@@ -28,6 +28,31 @@ test --test_output=errors
# Output as much information when a test exceeds a timeout
test --test_verbose_timeout_warnings
# These locations are cached on the CI
build --disk_cache=${CI_PROJECT_DIR}/.cache/bazel/disk
build --repository_cache=${CI_PROJECT_DIR}/.cache/bazel/repo
# Use remote cache/execution for our builds
# TODO: enable remote execution when runners support `bazel/ape`
# build --remote_executor=${CI_REMOTE_EXECUTOR}
build --remote_cache=${CI_REMOTE_CACHE}
build --remote_timeout=3600
build --remote_header=${CI_REMOTE_HEADER}
build --experimental_remote_cache_compression
build --jobs=${CI_REMOTE_JOBS}
# Upload results to the Build Event Service
build --bes_results_url=${CI_BES_RESULTS_URL}
build --bes_backend=${CI_BES_BACKEND}
# Add build metadata
build --build_metadata=REPO_URL=${CI_PROJECT_URL}
build --build_metadata=BRANCH_NAME=${CI_COMMIT_REF_NAME}
build --build_metadata=COMMIT_SHA=${CI_COMMIT_SHA}
build --build_metadata=HOST=${CI_SERVER_HOST}
build --build_metadata=ROLE=CI
build --build_metadata=USER=gitlab-ci
# Provide detailed timing information to the remote executor
build --noslim_profile
build --experimental_profile_include_target_label
build --experimental_profile_include_primary_output
# Eliminate duplicate references in the Build Event Stream
build --nolegacy_important_outputs
......@@ -5,6 +5,5 @@ build_test(
size = "small",
targets = [
"@ape-curl//:entrypoint",
"@ape-curl//:curl",
],
)