๋กœ์ผ“๐Ÿพ
article thumbnail

 

 

C/C++ ๊ธฐ๋ฐ˜์˜ ํ”„๋กœ์ ํŠธ๋ฅผ ๋นŒ๋“œํ•˜๋Š”๋ฐ ์žˆ์–ด ๋ณดํ†ต cmake ์™€ make ๋ฅผ ์ด์šฉํ•ด์„œ ๋นŒ๋“œ๋ฅผ ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

๊ฐ„๋žตํ•˜๊ฒŒ cmake ๋Š” CMakeList.txt ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ Makefile ๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๊ณ , make ๋Š” Makefile ๋ฅผ ํ†ตํ•ด ํ”„๋กœ์ ํŠธ๋ฅผ ๋นŒ๋“œํ•ฉ๋‹ˆ๋‹ค.

 

cmake ๋Š” ๋นŒ๋“œ๋ฅผ ์œ„ํ•œ ํ”„๋กœ์„ธ์Šค์ด๊ณ , make ๋Š” ์‹ค์ œ๋กœ ๋นŒ๋“œ๋ฅผ ํ•ด์ฃผ๋Š” ํ”„๋กœ์„ธ์Šค์ธ ์…ˆ์ด์ฃ .

 

๊ทธ๋Ÿฐ๋ฐ C/C++ ํ”„๋กœ์ ํŠธ๋ฅผ ๋นŒ๋“œํ•˜๋Š”๋ฐ, ๋นŒ๋“œ ์‹œ๊ฐ„์ด ๋Œ€๋žต 1์‹œ๊ฐ„ ์ •๋„ ์†Œ๋ชจ๋ฉ๋‹ˆ๋‹ค. ๋„ˆ๋ฌด ์˜ค๋ž˜๊ฑธ๋ ค์š”..

C/C++ ๋นŒ๋“œ 55๋ถ„ ์†Œ์š”

 

์ง„ํ–‰ํ•œ runner ๋Š” 2GB Memory ์˜ ์ธ์Šคํ„ด์Šค์ž…๋‹ˆ๋‹ค.

 

๋นŒ๋“œ ์‹œ๊ฐ„์„ ๋‹จ์ถ•์‹œํ‚ค๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. ๋นŒ๋“œ ์‹œ๊ฐ„์„ ๋‹จ์ถ•์‹œํ‚ค๊ธฐ ์œ„ํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ๊ฐ€์žฅ ๋จผ์ € ๋– ์˜ค๋ฅด๋Š” ๊ฒƒ์€ ๋ฐ”๋กœ ์บ์‹ฑ ์ž…๋‹ˆ๋‹ค.

๋งค๋ฒˆ ๊ฐ™์ด ํŒŒ์ผ์„ ๋นŒ๋“œํ•˜์ง€ ๋ง๊ณ , ๋ฐ˜๋ณต๋˜๋Š” ๋นŒ๋“œ ํŒŒ์ผ์„ ์บ์‹ฑํ•ด๋†“์œผ๋ฉด ์‹œ๊ฐ„์ด ๋งŽ์ด ๋‹จ์ถ•๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

๋‹คํ–‰ํžˆ C/C++ ํ”„๋กœ์ ํŠธ์˜ ๋นŒ๋“œ ์บ์‹ฑ ๊ด€๋ จํ•œ ํŒจํ‚ค์ง€๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ๋ฐ”๋กœ ccache ์ฃ .

 

ccache ๋Š” apt, yum ๊ณผ ๊ฐ™์€ ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ €๋กœ ์‰ฝ๊ฒŒ ์„ค์น˜๊ฐ€ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ๊ธฐ๋ณธ์ ์œผ๋กœ ~/.ccache ๊ฒฝ๋กœ๋ฅผ ์บ์‹œ ๋””๋ ‰ํ„ฐ๋ฆฌ๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ ccache ์™€ action/cache ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํšจ์œจ์ ์œผ๋กœ ์บ์‹ฑํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

action/cache ์— ๋Œ€ํ•ด ๊ถ๊ธˆํ•˜๋‹ค๋ฉด ์—ฌ๊ธฐ ์ฐธ๊ณ !

 

๊ทธ๋Ÿผ ๋ ›์ธ ๋‘๋”์ฝ”๋“œ~

 

์šฐ์„  action/cache ์ž…๋‹ˆ๋‹ค.

 

/home/runner/.ccache ๋ฅผ ์บ์‹œ ๋””๋ ‰ํ„ฐ๋ฆฌ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— action/cache ์˜ path ๋Š” /home/runner/.ccache ๋กœ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

key ๋Š” ํ•˜๊ณ ์‹ถ์€ ๊ฒƒ์œผ๋กœ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

jobs:
  linux-x64:
    runs-on: [ al2_x86_64 ]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Cache
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            /home/runner/.ccache
          key: ${{ runner.os }}-build-ccache
          restore-keys: |
            ccache
            ${{ runner.os }}-build-ccache

 

action/cache ๋ถ€๋ถ„์„ ์ด๊ฒŒ ๋์ž…๋‹ˆ๋‹ค.

 

์ด๋ฒˆ์—” cmake, make ๋ถ€๋ถ„์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

build.sh ๋ฅผ ์‹คํ–‰์‹œ์ผœ ์ค„ ๊ฒƒ์ด๊ณ , ๊ทธ ์•ˆ์— ์‹ค์ œ build ๋ช…๋ น์–ด๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

jobs:
  linux-x64:
    runs-on: [ al2_x86_64 ]
    steps:

		...

      - name: Build
        run: |
          bash build.sh

 

 

build.sh ์ž…๋‹ˆ๋‹ค.

ccache ๋ฅผ ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž๋กœ ์„ค์น˜ํ•ด์ฃผ๋ฉด /usr/lib/ccache ์— ์„ค์น˜๋ฉ๋‹ˆ๋‹ค. (ubuntu 20 ๊ธฐ์ค€)

cmake ์™€ make ๋ฅผ ์ง„ํ–‰ํ•  ๋•Œ ์ปดํŒŒ์ผ๋Ÿฌ๋ฅผ ccache gcc ์™€ ccache g++ ๋กœ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ช…๋ น์–ด ์ธ์ž๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ๋„˜๊ฒจ์ค๋‹ˆ๋‹ค.

#!/bin/bash

set -eu

# ubuntu 20 ๊ธฐ์ค€ ccache ๊ฒฝ๋กœ
declare -r C_COMPILER="/usr/lib/ccache/gcc"
declare -r CXX_COMPILER="/usr/lib/ccache/g++"

# ccache ์ปดํŒŒ์ผ๋Ÿฌ๋กœ ์ธ์ž๋กœ ๋„˜๊ฒจ์คŒ
cmake ./ -DCMAKE_C_COMPILER="${C_COMPILER}" -DCMAKE_CXX_COMPILER="${CXX_COMPILER}"
make -e CC="${C_COMPILER}" CXX="${CXX_COMPILER}"

 

์ข‹์Šต๋‹ˆ๋‹ค. ๋ชจ๋“  ์ค€๋น„๋Š” ๋๋‚œ ๊ฑฐ ๊ฐ™์•„์š”!

 

๊ทธ๋Ÿผ ์บ์‹ฑ์ด ์ œ๋Œ€๋กœ ๋๋Š” ์ง€ ํ™•์ธํ•ด๋ณด์ฃ !

 

action/cache ๋Š” ์„ฑ๊ณต์ ์ž…๋‹ˆ๋‹ค.

action/cache

 

๊ทธ๋Ÿผ ccache ๋ถ€๋ถ„๋„ ํ™•์ธํ•ด๋ณด์ฃ .

์•„๋ž˜ ์ด๋ฏธ์ง€๋Š” ccache -s ๋ผ๋Š” ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ–ˆ์„ ๋•Œ์˜ ๊ฒฐ๊ณผ์ด๋ฉฐ, ์ด๋ฅผ ํ†ตํ•ด ์‹ค์ œ๋กœ ์บ์‹ฑ์ด ๋˜์—ˆ๋Š” ์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

cache hit ๊ฐ€ ์˜ฌ๋ผ๊ฐ”๋‹ค๋ฉด ์„ฑ๊ณต์ ์œผ๋กœ ์บ์‹ฑ์ด ๋œ ๊ฒ๋‹ˆ๋‹ค.

ccache

์ตœ์ดˆ๋กœ ccache ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด cache hit ๊ฐ€ ์•„๋‹Œ cache miss ๋งŒ ๊ณ„์† ์˜ฌ๋ผ๊ฐˆ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ด์œ ๋Š” ์ตœ์ดˆ์—๋Š” ์บ์‹œ๋œ ํŒŒ์ผ์ด ์—†๊ธฐ ๋•Œ๋ฌธ์— ์บ์‹œ ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์–ด cache miss ๊ฐ€ ์˜ฌ๋ผ๊ฐ€๋Š” ๊ฒƒ์ด์ฃ .

๊ทธ๋ž˜์„œ ์ตœ์ดˆ์˜ ๋นŒ๋“œ๋ฅผ ์‹คํ–‰ํ•œ ํ›„ ๊ทธ ์ดํ›„์—๋Š” cache miss ๊ฐ€ ์•„๋‹Œ cache hit ์ด ์˜ฌ๋ผ๊ฐˆ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

action ์†Œ์š” ์‹œ๊ฐ„์œผ๋กœ๋„ ๋น„๊ตํ•ด๋ด…์‹œ๋‹ค.

์บ์‹ฑ ์ „ - C/C++ ๋นŒ๋“œ 55๋ถ„ ์†Œ์š”

 

์บ์‹ฑ ํ›„ - C/C++ ๋นŒ๋“œ 9๋ถ„ ์†Œ์š”

 

์˜ค~ 55๋ถ„์—์„œ 9๋ถ„์œผ๋กœ ๋งŽ์ด ๋‹จ์ถ•๋์–ด์š”!

 

๊ทธ๋Ÿผ ์ž์„ธํ•˜๊ฒŒ ์•Œ๊ธฐ ์œ„ํ•ด ์•ก์…˜ ๋‹จ์œ„๊ฐ€ ์•„๋‹Œ ์‹ค์ œ ๋นŒ๋“œ๋งŒ ์ˆ˜ํ–‰ํ•˜๋Š” ์Šคํ… ๋‹จ์œ„๋กœ ํ™•์ธํ•ด๋ณด์ฃ !

์บ์‹ฑ ์ „ - C/C++ ๋นŒ๋“œ 52๋ถ„ ์†Œ์š”

 

์บ์‹ฑ ํ›„ - C/C++ ๋นŒ๋“œ 6๋ถ„ ์†Œ์š”

 

์•ก์…˜ ๋‹จ์œ„์—์„  ์ถ”๊ฐ€์ ์ธ ์Šคํ… ๋ถ€๋ถ„๋“ค์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์‹œ๊ฐ„์ด ์žˆ์–ด์„œ ์ˆœ์ˆ˜ C/C++ ๋นŒ๋“œ๊ฐ€ ์ผ์–ด๋‚˜๋Š” ์Šคํ… ๋‹จ์œ„๋กœ ๋น„๊ตํ•ด๋ดค๋Š”๋ฐ,

 

๋ฌด๋ ค 8๋ฐฐ์ •๋„ ๋‹จ์ถ•์‹œ์ผฐ์Šต๋‹ˆ๋‹ค!!

 

์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” action/cache ์™€ ccache ๋ฅผ ์ด์šฉํ•ด์„œ C/C++ ํ”„๋กœ์ ํŠธ์˜ ๋นŒ๋“œ ์‹œ๊ฐ„์„ ๋Œ€ํญ ๋‹จ์ถ•์‹œ์ผœ๋ณด์•˜์Šต๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿฌ๋ฉด ์˜ค๋Š˜์€ ์—ฌ๊ธฐ๊นŒ์ง€~

profile on loading

Loading...