Skip to content

Commit

Permalink
build: replace nodejs with bun
Browse files Browse the repository at this point in the history
  • Loading branch information
LordTermor committed Jun 19, 2024
1 parent 0468955 commit cfb501b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
}
},
{
"name": "(yarn) Frontend",
"command": "yarn start",
"name": "(bun) Frontend",
"command": "bun dev",
"request": "launch",
"type": "node-terminal",
"cwd": "${workspaceFolder}/frontend"
"cwd": "${workspaceFolder}/web"
}
]
}
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ RUN apt-get update --yes && apt-get install --yes ca-certificates curl gnupg \
&& echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" > /etc/apt/sources.list.d/llvm.list \
&& curl --silent --location https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& curl --silent --location https://apt.kitware.com/keys/kitware-archive-latest.asc | gpg --dearmor -o /usr/share/keyrings/kitware-archive-keyring.gpg \
&& echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | tee /etc/apt/sources.list.d/kitware.list >/dev/null \
&& apt-get update --yes \
&& apt-get install --yes build-essential git cmake libssl-dev pip ninja-build lldb-17 clangd-17 clang-format-17 clang-17 libc++-17-dev libc++abi-17-dev nodejs zstd \
&& apt-get install --yes build-essential git cmake libssl-dev pip ninja-build lldb-17 clangd-17 clang-format-17 clang-17 libc++-17-dev libc++abi-17-dev nodejs zstd unzip \
&& rm -rf /var/lib/apt/lists/*

RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 100 && \
Expand All @@ -28,8 +26,7 @@ RUN pip install conan==1.63.0 \
&& conan profile update settings.compiler.version=17 default \
&& conan profile update settings.compiler.libcxx=libc++ default

RUN corepack enable \
&& corepack prepare yarn@stable --activate
RUN curl -fsSL https://bun.sh/install | bash

COPY conanfile.txt /conan/

Expand Down
51 changes: 51 additions & 0 deletions cmake/FindBun.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
set(_prev "${BUN_EXECUTABLE}")
find_program(BUN_EXECUTABLE bun DOC "Path to Bun, the all-in-one JavaScript runtime")

if(BUN_EXECUTABLE)
if(NOT _prev)
message(STATUS "Found Bun executable: ${BUN_EXECUTABLE}")
endif()
set(Bun_FOUND TRUE CACHE INTERNAL "")
else()
set(Bun_FOUND FALSE CACHE INTERNAL "")
if(Bun_FIND_REQUIRED)
message(FATAL_ERROR "Failed to find a Bun executable")
endif()
endif()

function(bun_run_command cmd working_dir)
message(STATUS "Running command: ${BUN_EXECUTABLE} ${cmd} at ${working_dir}")
execute_process(
COMMAND ${BUN_EXECUTABLE} ${cmd}
RESULT_VARIABLE result
ERROR_VARIABLE error
WORKING_DIRECTORY ${working_dir}
)
if (result)
message(FATAL_ERROR "Failed to run command: ${result}")
endif()
endfunction()

function(bun_add_vite_project package_name working_dir)
bun_run_command(install ${working_dir})

add_custom_target("${package_name}_build" ALL
COMMAND ${CMAKE_COMMAND} -E env BUILD_PATH='${CMAKE_CURRENT_BINARY_DIR}' ${BUN_EXECUTABLE} build
WORKING_DIRECTORY ${working_dir}
COMMENT "Building ${package_name}"
USES_TERMINAL
)

add_custom_command(
TARGET "${package_name}_build" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_BINARY_DIR}/bin/frontend)

add_custom_target("${package_name}_install"
COMMAND ${CMAKE_COMMAND} -E env BUILD_PATH='${CMAKE_CURRENT_BINARY_DIR}' ${BUN_EXECUTABLE} install
WORKING_DIRECTORY ${working_dir}
COMMENT "Installing packages for ${package_name}"
USES_TERMINAL
)
endfunction()

0 comments on commit cfb501b

Please sign in to comment.