[infra] Support for Alpine Linux Sysroot

Closes https://github.com/dart-lang/sdk/pull/51044

TEST=manually tested by the contributor

GitOrigin-RevId: 86c85da0680047e08caf81cc4c12098ae85c0d2b
Change-Id: I591d7e17ce3a87cf8ce8380c9511f70d738d44c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279267
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
This commit is contained in:
なつき 2023-01-19 10:36:51 +00:00 committed by Commit Queue
parent 9e4dc755cb
commit afe9219026
16 changed files with 178 additions and 54 deletions

3
build/.gitignore vendored
View file

@ -1,7 +1,8 @@
# Generated file containing information about the VS toolchain on Windows.
win_toolchain.json
# Pulled Debian sysroots.
# Pulled linux sysroots.
# Regex to prevent large when comparing checkouts with commits in which the
# sysroot has been rolled.
linux/alpine-linux-**-sysroot
linux/debian_**-sysroot

View file

@ -13,6 +13,8 @@ declare_args() {
}
}
import("//build/config/sysroot.gni")
import("//build/config/android/config.gni")
if (current_cpu == "arm") {
import("//build/config/arm.gni")
@ -262,21 +264,48 @@ config("compiler") {
# ------------------------------------
if (is_linux) {
if (is_clang) {
if (current_cpu == "arm") {
cflags += [ "--target=armv7-linux-gnueabihf" ]
ldflags += [ "--target=armv7-linux-gnueabihf" ]
} else if (current_cpu == "arm64") {
cflags += [ "--target=aarch64-linux-gnu" ]
ldflags += [ "--target=aarch64-linux-gnu" ]
} else if (current_cpu == "riscv32") {
cflags += [ "--target=riscv32-linux-gnu" ]
ldflags += [ "--target=riscv32-linux-gnu" ]
} else if (current_cpu == "riscv64") {
cflags += [ "--target=riscv64-linux-gnu" ]
ldflags += [ "--target=riscv64-linux-gnu" ]
} else if (current_cpu == "x86") {
cflags += [ "--target=i386-linux-gnu" ]
ldflags += [ "--target=i386-linux-gnu" ]
if (dart_sysroot == "alpine") {
# alpine linux target names can be found at:
# https://pkgs.alpinelinux.org/contents?file=stdc%2B%2B.h&name=libstdc%2B%2B-dev
if (current_cpu == "arm") {
cflags += [ "--target=armv7-alpine-linux-musleabihf" ]
ldflags += [ "--target=armv7-alpine-linux-musleabihf" ]
} else if (current_cpu == "arm64") {
cflags += [ "--target=aarch64-alpine-linux-musl" ]
ldflags += [ "--target=aarch64-alpine-linux-musl" ]
} else if (current_cpu == "riscv32") {
cflags += [ "--target=riscv32-alpine-linux-musl" ]
ldflags += [ "--target=riscv32-alpine-linux-musl" ]
} else if (current_cpu == "riscv64") {
cflags += [ "--target=riscv64-alpine-linux-musl" ]
ldflags += [ "--target=riscv64-alpine-linux-musl" ]
} else if (current_cpu == "x64") {
cflags += [ "--target=x86_64-alpine-linux-musl" ]
ldflags += [ "--target=x86_64-alpine-linux-musl" ]
} else if (current_cpu == "x86") {
cflags += [ "--target=i586-alpine-linux-musl" ]
ldflags += [ "--target=i586-alpine-linux-musl" ]
}
} else {
if (current_cpu == "arm") {
cflags += [ "--target=armv7-linux-gnueabihf" ]
ldflags += [ "--target=armv7-linux-gnueabihf" ]
} else if (current_cpu == "arm64") {
cflags += [ "--target=aarch64-linux-gnu" ]
ldflags += [ "--target=aarch64-linux-gnu" ]
} else if (current_cpu == "riscv32") {
cflags += [ "--target=riscv32-linux-gnu" ]
ldflags += [ "--target=riscv32-linux-gnu" ]
} else if (current_cpu == "riscv64") {
cflags += [ "--target=riscv64-linux-gnu" ]
ldflags += [ "--target=riscv64-linux-gnu" ]
} else if (current_cpu == "x64") {
cflags += [ "--target=x86_64-linux-gnu" ]
ldflags += [ "--target=x86_64-linux-gnu" ]
} else if (current_cpu == "x86") {
cflags += [ "--target=i386-linux-gnu" ]
ldflags += [ "--target=i386-linux-gnu" ]
}
}
}
}
@ -368,7 +397,7 @@ config("compiler") {
# changes since artifacts from an older version of the toolchain may or may
# not be compatible with newer ones. To achieve this, we insert a synthetic
# define into the compile line.
if (is_clang && (is_linux || is_mac)) {
if (is_clang && (is_linux || is_mac) && dart_sysroot != "alpine") {
if (is_linux && host_cpu == "arm64") {
toolchain_stamp_file =
"//buildtools/linux-arm64/clang/.versions/clang.cipd_version"
@ -643,9 +672,12 @@ config("chromium_code") {
cflags = [
"-Wall",
"-Wextra",
"-Werror",
]
if (dart_sysroot != "alpine") {
cflags += [ "-Werror" ]
}
defines = []
if (!using_sanitizer && !is_clang) {
# _FORTIFY_SOURCE isn't really supported by Clang now, see

View file

@ -26,9 +26,23 @@ config("sdk") {
],
"value") ]
if (dart_sysroot == "alpine") {
# When using the alpine sysroot, prefers lld as linker.
if (is_clang) {
ldflags += [ "-fuse-ld=lld" ]
}
# Statically link libstdc++ and libgcc as minimal alpine installation
# do not have them by default.
ldflags += [
"-static-libgcc",
"-static-libstdc++",
]
}
# When using the pulled Debian sysroot with gcc, we have to specify these
# excplicitly.
if (dart_use_debian_sysroot && !is_clang) {
if (dart_sysroot == "debian" && !is_clang) {
cflags += [
"-I=/usr/include/c++/4.8",
"-I=/usr/include/c++/4.8/i486-linux-gnu",

View file

@ -10,25 +10,48 @@ declare_args() {
# the target toolchain.
target_sysroot = ""
# Whether the Debian sysroot should be used.
dart_use_debian_sysroot = false
# The type of sysroot to be used. Empty string means no sysroot.
# Supported sysroots: ["alpine","debian"]
dart_sysroot = ""
}
if (is_linux && dart_use_debian_sysroot) {
if (current_cpu == "x86") {
target_sysroot =
rebase_path("//build/linux/debian_stretch_i386-sysroot", root_build_dir)
} else if (current_cpu == "x64") {
target_sysroot =
rebase_path("//build/linux/debian_stretch_amd64-sysroot", root_build_dir)
} else if (current_cpu == "arm") {
target_sysroot =
rebase_path("//build/linux/debian_stretch_arm-sysroot", root_build_dir)
} else if (current_cpu == "arm64") {
target_sysroot =
rebase_path("//build/linux/debian_stretch_arm64-sysroot", root_build_dir)
} else {
print("There is no Debian sysroot present for $current_cpu")
if (is_linux) {
if (dart_sysroot == "alpine") {
if (current_cpu == "x86") {
target_sysroot =
rebase_path("//build/linux/alpine-linux-x86-sysroot", root_build_dir)
} else if (current_cpu == "x64") {
target_sysroot =
rebase_path("//build/linux/alpine-linux-x86_64-sysroot", root_build_dir)
} else if (current_cpu == "arm") {
target_sysroot =
rebase_path("//build/linux/alpine-linux-armv7-sysroot", root_build_dir)
} else if (current_cpu == "arm64") {
target_sysroot =
rebase_path("//build/linux/alpine-linux-aarch64-sysroot", root_build_dir)
} else {
print("There is no $dart_sysroot sysroot present for $current_cpu")
assert(false)
}
} else if (dart_sysroot == "debian") {
if (current_cpu == "x86") {
target_sysroot =
rebase_path("//build/linux/debian_stretch_i386-sysroot", root_build_dir)
} else if (current_cpu == "x64") {
target_sysroot =
rebase_path("//build/linux/debian_stretch_amd64-sysroot", root_build_dir)
} else if (current_cpu == "arm") {
target_sysroot =
rebase_path("//build/linux/debian_stretch_arm-sysroot", root_build_dir)
} else if (current_cpu == "arm64") {
target_sysroot =
rebase_path("//build/linux/debian_stretch_arm64-sysroot", root_build_dir)
} else {
print("There is no $dart_sysroot sysroot present for $current_cpu")
assert(false)
}
} else if (dart_sysroot != "") {
print("There is no $dart_sysroot sysroot support")
assert(false)
}
}

View file

@ -0,0 +1,19 @@
# Alpine Linux Sysroots
This directory contains a script for community contributed alpine linux sysroot support.
On Alpine Linux, run the script directly:
``` sh
./build/linux/alpine_sysroot_scripts/install-sysroot.sh
```
On other linux systems, you can run the script with Alpine Linux container:
``` sh
docker container run --rm \
--volume "$PWD:$PWD" \
--workdir "$PWD" \
docker.io/library/alpine \
./build/linux/alpine_sysroot_scripts/install-sysroot.sh
```

View file

@ -0,0 +1,28 @@
#!/bin/sh
# Install Alpine sysroots for building with musl libc.
#
# Sysroots will be installed into //build/linux/alpine-linux-$arch-sysroot
#
# Architectures to be installed can be configured at the end of the script
#
# List of available architectures can be found at:
# https://pkgs.alpinelinux.org/packages?name=alpine-base
set -e
if test ! -f /etc/alpine-release; then
echo "Error: This script must be run directly on alpine linux or inside alpine linux container." >&2
exit 1
fi
SCRIPT="$(readlink -f -- "$0")"
WORKDIR="$(dirname -- "$(dirname -- "$SCRIPT")")"
xargs -n 1 -- sh -xc 'apk add --root "$1/alpine-linux-$2-sysroot" --repositories-file /etc/apk/repositories --allow-untrusted --arch "$2" --no-cache --no-scripts --initdb -- alpine-base alpine-sdk linux-headers' -- "$WORKDIR" <<'EOF'
aarch64
armv7
x86
x86_64
EOF

View file

@ -21,7 +21,10 @@ if (use_goma) {
compiler_prefix = ""
}
if (host_cpu == "arm64") {
# Google's clang does not work for alpine, use alpine's system clang
if (dart_sysroot == "alpine") {
rebased_clang_dir = "/usr/bin"
} else if (host_cpu == "arm64") {
rebased_clang_dir =
rebase_path("//buildtools/linux-arm64/clang/bin", root_build_dir)
} else {

View file

@ -6,6 +6,8 @@ import("../sdk_args.gni")
import("configs.gni")
import("runtime_args.gni")
import("//build/config/sysroot.gni")
if (is_fuchsia) {
import("//build/fuchsia/sdk.gni")
}
@ -211,7 +213,6 @@ config("dart_config") {
}
} else {
cflags = [
"-Werror",
"-Wall",
"-Wextra", # Also known as -W.
"-Wno-unused-parameter",
@ -225,6 +226,9 @@ config("dart_config") {
"-fno-rtti",
"-fno-exceptions",
]
if (dart_sysroot != "alpine") {
cflags += [ "-Werror" ]
}
if (is_clang) {
cflags += [
"-Wimplicit-fallthrough",

View file

@ -114,7 +114,7 @@ int Thread::Start(const char* name,
return 0;
}
const ThreadId Thread::kInvalidThreadId = reinterpret_cast<ThreadId>(NULL);
const ThreadId Thread::kInvalidThreadId = static_cast<ThreadId>(NULL);
intptr_t Thread::GetMaxStackSize() {
const int kStackSize = (128 * kWordSize * KB);

View file

@ -1286,7 +1286,7 @@ static Dart_Isolate CreateIsolate(IsolateGroup* group,
if (error != NULL) {
*error = Utils::StrDup("Isolate creation failed");
}
return reinterpret_cast<Dart_Isolate>(NULL);
return static_cast<Dart_Isolate>(NULL);
}
Thread* T = Thread::Current();
@ -1330,7 +1330,7 @@ static Dart_Isolate CreateIsolate(IsolateGroup* group,
}
Dart::ShutdownIsolate();
return reinterpret_cast<Dart_Isolate>(NULL);
return static_cast<Dart_Isolate>(NULL);
}
static bool IsServiceOrKernelIsolateName(const char* name) {

View file

@ -17,7 +17,7 @@ VM_UNIT_TEST_CASE(IsolateCurrent) {
Dart_Isolate isolate = TestCase::CreateTestIsolate();
EXPECT_EQ(isolate, Dart_CurrentIsolate());
Dart_ShutdownIsolate();
EXPECT_EQ(reinterpret_cast<Dart_Isolate>(NULL), Dart_CurrentIsolate());
EXPECT_EQ(static_cast<Dart_Isolate>(NULL), Dart_CurrentIsolate());
}
// Test to ensure that an exception is thrown if no isolate creation

View file

@ -62,7 +62,7 @@ TEST_CASE(Log_Basic) {
test_output_ = NULL;
Log* log = new Log(TestPrinter);
EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_);
EXPECT_EQ(static_cast<const char*>(NULL), test_output_);
log->Print("Hello %s", "World");
EXPECT_STREQ("Hello World", test_output_);
@ -74,23 +74,23 @@ TEST_CASE(Log_Block) {
test_output_ = NULL;
Log* log = new Log(TestPrinter);
EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_);
EXPECT_EQ(static_cast<const char*>(NULL), test_output_);
{
LogBlock ba(thread, log);
log->Print("APPLE");
EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_);
EXPECT_EQ(static_cast<const char*>(NULL), test_output_);
{
LogBlock ba(thread, log);
log->Print("BANANA");
EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_);
EXPECT_EQ(static_cast<const char*>(NULL), test_output_);
}
EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_);
EXPECT_EQ(static_cast<const char*>(NULL), test_output_);
{
LogBlock ba(thread, log);
log->Print("PEAR");
EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_);
EXPECT_EQ(static_cast<const char*>(NULL), test_output_);
}
EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_);
EXPECT_EQ(static_cast<const char*>(NULL), test_output_);
}
EXPECT_STREQ("APPLEBANANAPEAR", test_output_);
delete log;

View file

@ -157,9 +157,9 @@ int OSThread::Start(const char* name,
return 0;
}
const ThreadId OSThread::kInvalidThreadId = reinterpret_cast<ThreadId>(NULL);
const ThreadId OSThread::kInvalidThreadId = static_cast<ThreadId>(NULL);
const ThreadJoinId OSThread::kInvalidThreadJoinId =
reinterpret_cast<ThreadJoinId>(NULL);
static_cast<ThreadJoinId>(NULL);
ThreadLocalKey OSThread::CreateThreadLocal(ThreadDestructor destructor) {
pthread_key_t key = kUnsetThreadLocalKey;

View file

@ -198,7 +198,7 @@ StringPtr Symbols::FromUTF8(Thread* thread,
const uint8_t* utf8_array,
intptr_t array_len) {
if (array_len == 0 || utf8_array == NULL) {
return FromLatin1(thread, reinterpret_cast<uint8_t*>(NULL), 0);
return FromLatin1(thread, static_cast<uint8_t*>(NULL), 0);
}
Utf8::Type type;
intptr_t len = Utf8::CodeUnitCount(utf8_array, array_len, &type);

View file

@ -883,7 +883,7 @@ TimelineEvent* TimelineStream::StartEvent() {
TimelineEventScope::TimelineEventScope(TimelineStream* stream,
const char* label)
: StackResource(reinterpret_cast<Thread*>(NULL)),
: StackResource(static_cast<Thread*>(NULL)),
stream_(stream),
label_(label),
enabled_(false) {

View file

@ -302,7 +302,7 @@ def ToGnArgs(args, mode, arch, target_os, sanitizer, verify_sdk_hash):
# Setup the user-defined sysroot.
if UseSysroot(args, gn_args):
gn_args['dart_use_debian_sysroot'] = True
gn_args['dart_sysroot'] = 'debian'
else:
sysroot = TargetSysroot(args)
if sysroot: