Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vcpkg-tool-gn] Build gn from source on 16 KiB page arm64-Linux #39474

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 84 additions & 17 deletions ports/vcpkg-tool-gn/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)

set(program GN)
set(search_names gn gn.exe)
set(paths_to_search "${CURRENT_PACKAGES_DIR}/tools/gn")
set(build_gn_from_source FALSE)

set(cipd_download_gn "https://chrome-infra-packages.appspot.com/dl/gn/gn")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
EXEC_PROGRAM(uname ARGS -m OUTPUT_VARIABLE HOST_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
if(HOST_ARCH STREQUAL "aarch64")
set(program_version "3bH3TSyghUqRj8To2aE9yy4D_k_zCkymWkbwzaeEk34C")
set(gn_platform "linux-arm64")
set(download_sha512 "36604e7ca146f21a80c9a2463dcf09caa0c03c05507d93497884cb28da3582b9a695008d01be814e523e4a4982300ee7c717c2aa7fddbc8156736ec6b4251f9c")
include(${CMAKE_CURRENT_LIST_DIR}/z_vcpkg_get_host_page_size.cmake)
z_vcpkg_get_host_page_size()
if (NOT Z_VCPKG_HOST_PAGE_SIZE EQUAL 4096)
# Google doesn't provide a prebuilt binary for 16 KiB page size platforms
# such as Asahi Linux
set(build_gn_from_source TRUE)
else()
set(program_version "3bH3TSyghUqRj8To2aE9yy4D_k_zCkymWkbwzaeEk34C")
set(gn_platform "linux-arm64")
set(download_sha512 "36604e7ca146f21a80c9a2463dcf09caa0c03c05507d93497884cb28da3582b9a695008d01be814e523e4a4982300ee7c717c2aa7fddbc8156736ec6b4251f9c")
endif()
else()
set(program_version "5v1Aw5ofON_P9Ds3nj1TzasiNIkS9eebfC3xe1lgCakC")
set(gn_platform "linux-amd64")
Expand All @@ -34,18 +41,78 @@ else()
set(download_sha512 "2f471d4fa5f56cd72c43c5f2824f37a1baff3f26cd6c1ed43fe106153d0e654a4fb1460b01794ca3dae3104dfade81420fe1da04473e782eebab47909c9a566b")
endif()

set(download_urls "${cipd_download_gn}/${gn_platform}/+/${program_version}")
set(download_filename "gn-${gn_platform}.zip")
vcpkg_download_distfile(archive_path
URLS ${download_urls}
SHA512 "${download_sha512}"
FILENAME "${download_filename}"
)
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/gn")
vcpkg_execute_in_download_mode(
COMMAND "${CMAKE_COMMAND}" -E tar xzf "${archive_path}"
WORKING_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/gn"
)
if (build_gn_from_source)
set(program_version "b2afae122eeb6ce09c52d63f67dc53fc517dbdc8")

vcpkg_from_git(
OUT_SOURCE_PATH SOURCE_PATH
URL "https://gn.googlesource.com/gn"
REF "${program_version}"
)

vcpkg_find_acquire_program(PYTHON3)
vcpkg_find_acquire_program(NINJA)
vcpkg_find_acquire_program(CLANG)

message(STATUS "Building gn from source")

# FIXME: Is there a proper way to pass env vars to the process?
vcpkg_execute_required_process(
COMMAND env CC="${CLANG}" CXX="${CLANG}++" "${PYTHON3}" build/gen.py
--no-static-libstdc++
--allow-warnings
--no-last-commit-position
--out-path=${CURRENT_BUILDTREES_DIR}/out
WORKING_DIRECTORY "${SOURCE_PATH}"
LOGNAME "gn-generate"
)

# FIXME: GN requires a git repo and a tag named ROOT_TAG to be present to generate this file itself
file(WRITE "${CURRENT_BUILDTREES_DIR}/out/last_commit_position.h" "
// Generated by build/gen.py.

#ifndef OUT_LAST_COMMIT_POSITION_H_
#define OUT_LAST_COMMIT_POSITION_H_

#define LAST_COMMIT_POSITION_NUM 2175
#define LAST_COMMIT_POSITION \"2175 (b2afae122eeb)\"

#endif // OUT_LAST_COMMIT_POSITION_H_
")

vcpkg_execute_required_process(
COMMAND env CC="${CLANG}" CXX="${CLANG}++" "${NINJA}"
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/out"
LOGNAME "gn-build"
)

file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/gn")
file(INSTALL "${CURRENT_BUILDTREES_DIR}/out/gn"
DESTINATION "${CURRENT_PACKAGES_DIR}/tools/gn"
FILE_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
set(VCPKG_POLICY_EMPTY_INCLUDE_FOLDER enabled)
else()
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)

set(download_urls "${cipd_download_gn}/${gn_platform}/+/${program_version}")
set(download_filename "gn-${gn_platform}.zip")
vcpkg_download_distfile(archive_path
URLS ${download_urls}
SHA512 "${download_sha512}"
FILENAME "${download_filename}"
)
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/gn")
vcpkg_execute_in_download_mode(
COMMAND "${CMAKE_COMMAND}" -E tar xzf "${archive_path}"
WORKING_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/gn"
)
endif()

z_vcpkg_find_acquire_program_find_internal("${program}"
PATHS ${paths_to_search}
Expand Down
2 changes: 1 addition & 1 deletion ports/vcpkg-tool-gn/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vcpkg-tool-gn",
"version-date": "2024-02-22",
"version-date": "2024-06-23",
"description": "GN build system",
"homepage": "https://gn.googlesource.com/gn/",
"license": null,
Expand Down
70 changes: 70 additions & 0 deletions ports/vcpkg-tool-gn/z_vcpkg_get_host_page_size.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
include_guard(GLOBAL)
function(z_vcpkg_get_host_page_size)
if(NOT TARGET_TRIPLET STREQUAL _HOST_TRIPLET)
message(FATAL_ERROR "z_vcpkg_get_host_page_size() must only be called from a host port build")
endif()

set(BUILD_DIR "${CURRENT_BUILDTREES_DIR}/host_page_size")
set(SRC "${BUILD_DIR}/get_host_page_size.c")

file(WRITE "${SRC}" "
#include <stdlib.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>

#if defined __APPLE__
#include <sys/sysctl.h>
#elif defined __linux__
#include <stdio.h>
#elif (defined(__FreeBSD__) || defined(__NetBSD__))
#include <sys/param.h>
#else
#error unrecognized platform
#endif
#endif

#include <stdio.h>
int main() {
long result = 0;
size_t cache_line_size = 0;
#ifdef _WIN32
SYSTEM_INFO si;
DWORD bufferSize = 0;
DWORD i = 0;
SYSTEM_LOGICAL_PROCESSOR_INFORMATION *buffer = 0;

GetSystemInfo(&si);
result = si.dwSizes;
#else
result = sysconf(_SC_PAGESIZE);
#endif
printf(\"%ld\", result);

return 0;
}
")

# FIXME: Is there a vcpkg approved :tm: try_run replacement?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need it.

  • Make a project subdir with regular CMakeLists.txt.
  • Use vcpkg_cmake_configure(SOURCE_PATH "${CURRENT_PORT_DIR}/project" ...) - it will pass the actual toolchain settings.
    Make the configuration always succeed, and make it write a result file (aligned via OPTIONS "-DRESULT_FILE=${CURRENT_BUILDTREES_DIR}/result-${TARGET_TRIPLET}.cmake") with the desired information.
  • Load the result file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping @ADKaster for response. Can you address the review suggestions? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @LilyWangLL , sorry for the late reply. I don't think I'll have the capacity to address the comments on this issue.

vcpkg_find_acquire_program(CLANG)
vcpkg_execute_required_process(
COMMAND "${CLANG}" -o "${BUILD_DIR}/get_host_page_size" "${SRC}"
WORKING_DIRECTORY "${BUILD_DIR}"
LOGNAME "get_host_page_size-compile"
)

execute_process(
COMMAND "${BUILD_DIR}/get_host_page_size"
OUTPUT_VARIABLE RUN_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE RUN_ERROR
)

if (NOT RUN_ERROR STREQUAL "")
message(FATAL_ERROR "Error running get_host_page_size: ${RUN_ERROR}")
endif()

message(STATUS "Host page size: ${RUN_OUTPUT}")
set(Z_VCPKG_HOST_PAGE_SIZE "${RUN_OUTPUT}" PARENT_SCOPE)
endfunction()
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -9153,7 +9153,7 @@
"port-version": 0
},
"vcpkg-tool-gn": {
"baseline": "2024-02-22",
"baseline": "2024-06-23",
"port-version": 0
},
"vcpkg-tool-gyp-next": {
Expand Down
5 changes: 5 additions & 0 deletions versions/v-/vcpkg-tool-gn.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "962fc90715e5079ef969b768ebba2c3521a9071f",
"version-date": "2024-06-23",
"port-version": 0
},
{
"git-tree": "2d1a5157488930321ba70a7990971c317dc02548",
"version-date": "2024-02-22",
Expand Down