From e85cd5c562ea1c97b43d630d4916a68e6a6194eb Mon Sep 17 00:00:00 2001 From: Hodong Kim Date: Sun, 25 Aug 2024 12:26:23 +0900 Subject: [PATCH] Support for FreeBSD --- BUILD.gn | 18 ++++++++++------ bench/SkSLBench.cpp | 15 +++++++++++++ gn/BUILDCONFIG.gn | 1 + gn/skia/BUILD.gn | 6 +++--- gn/toolchain/BUILD.gn | 2 +- src/utils/BUILD.bazel | 1 + src/utils/SkGetExecutablePath_freebsd.cpp | 26 +++++++++++++++++++++++ tools/git-sync-deps | 22 ++++++++++++++----- tools/window/BUILD.gn | 8 +++---- 9 files changed, 79 insertions(+), 20 deletions(-) create mode 100644 src/utils/SkGetExecutablePath_freebsd.cpp diff --git a/BUILD.gn b/BUILD.gn index a24682f6eb..c06448bf60 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -35,7 +35,7 @@ config("skia_public") { if (is_component_build) { defines += [ "SKIA_DLL" ] } - if (is_fuchsia || is_linux) { + if (is_fuchsia || is_linux || is_freebsd) { defines += [ "SK_R32_SHIFT=16" ] } if (skia_enable_optimize_size) { @@ -565,6 +565,8 @@ if (skia_compile_modules) { sources += [ "src/utils/SkGetExecutablePath_mac.cpp" ] } else if (is_linux || is_android) { sources += [ "src/utils/SkGetExecutablePath_linux.cpp" ] + } else if (is_freebsd) { + sources += [ "src/utils/SkGetExecutablePath_freebsd.cpp" ] } if (is_win) { sources += skia_ports_windows_sources @@ -692,6 +694,8 @@ if (skia_compile_sksl_tests) { sources += [ "src/utils/SkGetExecutablePath_mac.cpp" ] } else if (is_linux || is_android) { sources += [ "src/utils/SkGetExecutablePath_linux.cpp" ] + } else if (is_freebsd) { + sources += [ "src/utils/SkGetExecutablePath_freebsd.cpp" ] } if (is_win) { sources += skia_ports_windows_sources @@ -975,7 +979,7 @@ optional("gpu") { } } else if (skia_use_webgl) { sources += [ "src/gpu/ganesh/gl/webgl/GrGLMakeNativeInterface_webgl.cpp" ] - } else if (is_linux && skia_use_x11) { + } else if ((is_linux || is_freebsd) && skia_use_x11) { sources += [ "src/gpu/ganesh/gl/glx/GrGLMakeGLXInterface.cpp", "src/gpu/ganesh/gl/glx/GrGLMakeNativeInterface_glx.cpp", @@ -1549,7 +1553,7 @@ skia_component("skia") { ] } - if (is_linux || is_wasm) { + if (is_linux || is_freebsd || is_wasm) { sources += [ "src/ports/SkDebug_stdio.cpp" ] if (skia_use_egl) { libs += [ "GLESv2" ] @@ -1978,7 +1982,7 @@ if (skia_enable_tools) { if (is_android || skia_use_egl) { sources += [ "tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp" ] libs += [ "EGL" ] - } else if (is_linux) { + } else if (is_linux || is_freebsd) { sources += [ "tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp" ] libs += [ "GLU", @@ -2343,7 +2347,7 @@ if (skia_enable_tools) { ] } - if (is_linux || is_mac || skia_enable_optimize_size) { + if (is_linux || is_freebsd || is_mac || skia_enable_optimize_size) { if (skia_enable_skottie) { test_app("skottie_tool") { deps = [ "modules/skottie:tool" ] @@ -2798,7 +2802,7 @@ if (skia_enable_tools) { "tools/sk_app/android/surface_glue_android.h", ] libs += [ "android" ] - } else if (is_linux) { + } else if (is_linux || is_freebsd) { sources += [ "tools/sk_app/unix/Window_unix.cpp", "tools/sk_app/unix/Window_unix.h", @@ -2848,7 +2852,7 @@ if (skia_enable_tools) { } } - if (!skia_use_vulkan && (is_mac || is_linux || is_win)) { + if (!skia_use_vulkan && (is_mac || is_linux || is_freebsd || is_win)) { test_app("fiddle_examples") { sources = [ "tools/fiddle/all_examples.cpp", diff --git a/bench/SkSLBench.cpp b/bench/SkSLBench.cpp index 1ad9cbab2c..72d8618498 100644 --- a/bench/SkSLBench.cpp +++ b/bench/SkSLBench.cpp @@ -624,10 +624,25 @@ void main() #if defined(SK_BUILD_FOR_UNIX) +#ifdef __FreeBSD__ +#include +#include + +static int64_t heap_bytes_used() { + size_t allocated; + size_t len = sizeof (allocated); + + if (!mallctl ("stats.allocated", &allocated, &len, NULL, 0)) + return allocated; + + return -1; +} +#else #include static int64_t heap_bytes_used() { return (int64_t)mallinfo().uordblks; } +#endif #elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) diff --git a/gn/BUILDCONFIG.gn b/gn/BUILDCONFIG.gn index 146ad60b4b..f8f09adb85 100644 --- a/gn/BUILDCONFIG.gn +++ b/gn/BUILDCONFIG.gn @@ -68,6 +68,7 @@ is_fuchsia = current_os == "fuchsia" is_ios = current_os == "ios" || current_os == "tvos" is_tvos = current_os == "tvos" is_linux = current_os == "linux" +is_freebsd = current_os == "freebsd" is_mac = current_os == "mac" is_wasm = current_os == "wasm" is_win = current_os == "win" diff --git a/gn/skia/BUILD.gn b/gn/skia/BUILD.gn index f250c29465..f57b19e509 100644 --- a/gn/skia/BUILD.gn +++ b/gn/skia/BUILD.gn @@ -259,7 +259,7 @@ config("default") { } } - if (is_linux) { + if (is_linux || is_freebsd) { libs += [ "pthread" ] } @@ -375,7 +375,7 @@ config("default") { ldflags += [ "-fsanitize=$sanitizers" ] } - if (is_linux) { + if (is_linux || is_freebsd) { cflags_cc += [ "-stdlib=libc++" ] ldflags += [ "-stdlib=libc++" ] } @@ -751,7 +751,7 @@ config("executable") { ] } else if (is_mac) { ldflags = [ "-Wl,-rpath,@loader_path/." ] - } else if (is_linux) { + } else if (is_linux || is_freebsd) { ldflags = [ "-rdynamic", "-Wl,-rpath,\$ORIGIN", diff --git a/gn/toolchain/BUILD.gn b/gn/toolchain/BUILD.gn index 4d4abc952f..5f15599b1b 100644 --- a/gn/toolchain/BUILD.gn +++ b/gn/toolchain/BUILD.gn @@ -323,7 +323,7 @@ template("gcc_like_toolchain") { rspfile = "{{output}}.rsp" rspfile_content = "{{inputs}}" rm_py = rebase_path("../rm.py") - command = "$shell python3 \"$rm_py\" \"{{output}}\" && $ar rcs {{output}} @$rspfile" + command = "$shell python3 \"$rm_py\" \"{{output}}\" && $ar rcs {{output}} `cat $rspfile`" } outputs = diff --git a/src/utils/BUILD.bazel b/src/utils/BUILD.bazel index b1e2d1d0e0..1a968f710c 100644 --- a/src/utils/BUILD.bazel +++ b/src/utils/BUILD.bazel @@ -173,6 +173,7 @@ skia_cc_library( "@platforms//os:windows": ["SkGetExecutablePath_win.cpp"], "@platforms//os:macos": ["SkGetExecutablePath_mac.cpp"], "@platforms//os:linux": ["SkGetExecutablePath_linux.cpp"], + "@platforms//os:freebsd": ["SkGetExecutablePath_freebsd.cpp"], }), hdrs = ["SkGetExecutablePath.h"], visibility = [ diff --git a/src/utils/SkGetExecutablePath_freebsd.cpp b/src/utils/SkGetExecutablePath_freebsd.cpp new file mode 100644 index 0000000000..5945aa1f69 --- /dev/null +++ b/src/utils/SkGetExecutablePath_freebsd.cpp @@ -0,0 +1,26 @@ +/* + * Copyright 2022 Google Inc. + * Copyright (C) 2023,2024 Hodong Kim + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "tools/SkGetExecutablePath.h" +#include +#include + +std::string SkGetExecutablePath() { + int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; + std::string result(PATH_MAX, '\0'); + size_t len = result.size() - 1; + + int retval = sysctl(mib, 4, result.data(), &len, NULL, 0); + + if (retval < 0 || static_cast(len) >= PATH_MAX - 1) { + result.clear(); + } else { + result.resize(len); + } + return result; +} diff --git a/tools/git-sync-deps b/tools/git-sync-deps index 1efb98d055..d569851685 100755 --- a/tools/git-sync-deps +++ b/tools/git-sync-deps @@ -265,13 +265,25 @@ def main(argv): return 1 git_sync_deps(deps_file_path, argv, shallow, verbose) - subprocess.check_call( - [sys.executable, - os.path.join(os.path.dirname(deps_file_path), 'bin', 'fetch-gn')]) - if not skip_emsdk: + os_name = sys.platform + +# install gn + if os_name == 'freebsd14': + subprocess.run(["sudo", "pkg", "install", "gn"]) + subprocess.run(["ln", "-sf", "/usr/local/bin/gn", "bin/gn"]) + else: subprocess.check_call( [sys.executable, - os.path.join(os.path.dirname(deps_file_path), 'bin', 'activate-emsdk')]) + os.path.join(os.path.dirname(deps_file_path), 'bin', 'fetch-gn')]) + +# install emsdk + if not skip_emsdk: + if os_name == 'freebsd14': + subprocess.run(["sudo", "pkg", "install", "emscripten"]) + else: + subprocess.check_call( + [sys.executable, + os.path.join(os.path.dirname(deps_file_path), 'bin', 'activate-emsdk')]) return 0 diff --git a/tools/window/BUILD.gn b/tools/window/BUILD.gn index 4a30186dbd..7dfa84af71 100644 --- a/tools/window/BUILD.gn +++ b/tools/window/BUILD.gn @@ -38,7 +38,7 @@ skia_component("window") { "android/WindowContextFactory_android.h", ] libs += [ "android" ] - } else if (is_linux) { + } else if (is_linux || is_freebsd) { sources += [ "unix/RasterWindowContext_unix.cpp", "unix/RasterWindowContext_unix.h", @@ -72,7 +72,7 @@ skia_component("window") { } if (is_android) { sources += [ "android/GLWindowContext_android.cpp" ] - } else if (is_linux) { + } else if (is_linux || is_freebsd) { sources += [ "unix/GaneshGLWindowContext_unix.cpp", "unix/GaneshGLWindowContext_unix.h", @@ -123,7 +123,7 @@ skia_component("window") { if (skia_enable_graphite) { sources += [ "android/GraphiteVulkanWindowContext_android.cpp" ] } - } else if (is_linux) { + } else if (is_linux || is_freebsd) { sources += [ "unix/GaneshVulkanWindowContext_unix.cpp", "unix/GaneshVulkanWindowContext_unix.h", @@ -178,7 +178,7 @@ skia_component("window") { } if (skia_use_dawn) { - if (is_linux) { + if (is_linux || is_freebsd) { if (dawn_enable_vulkan) { defines = [ "VK_USE_PLATFORM_XCB_KHR" ] libs += [ "X11-xcb" ] -- 2.45.2