Không thể link libpq.lib khi chạy CICD trong Github Actions

Xin chào mọi người,

Hiện tại mình đang apply CICD cho con pet project nhưng lại gặp vấn đề với Github Actions. Cụ thể là khi chạy CICD trên Windows mình gặp phải lỗi sau

error: linking with `link.exe` failed: exit code: 1181
##[error]  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Tools\\MSVC\\14.25.28610\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.0.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.1.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.10.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.11.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.12.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.13.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.14.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.15.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.2.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.3.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.4.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.5.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.6.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.7.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.8.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.migrations_macros.ctw4naej-cgu.9.rcgu.o" "/OUT:D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.dll" "/DEF:C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\rustcUpJ4jM\\lib.def" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.f6zvnk6ziim47lv.rcgu.o" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.4rv9bqohxyn58o8i.rcgu.o" "/OPT:REF,ICF" "/DEBUG" "/NATVIS:C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis" "/LIBPATH:D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps" "/LIBPATH:C:/STRAWB~1/c/lib" "/LIBPATH:C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libsyn-c5ebba226908cc59.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libquote-61df1bb6d0ac5528.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libproc_macro2-1fd0601ba7c5fa05.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libunicode_xid-b877fb07c9f3d1e0.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libproc_macro-c74d15e0ebc652b4.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libmigrations_internals-a4e22c942ceea495.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libdiesel-a963c2263c0a224d.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libpq_sys-560808b9b631dab1.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libchrono-ea811b36a3740c3b.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libserde-378f9eabf41260b9.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libnum_integer-fc61db76106af4ab.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libnum_traits-5a8eb9d9fdacb93a.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libtime-cbf9cdf272908761.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libr2d2-71391c9cd8094d5c.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libscheduled_thread_pool-76ddeaa20c370841.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libparking_lot-2173ed486a291f99.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libparking_lot_core-bcbdb90d08084ad9.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libwinapi-b5c8b33782aeb604.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libsmallvec-5d75d5a511c4a6df.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\liblock_api-ab93be3eeaf6083a.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libscopeguard-f1b53d20c1374651.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\liblog-8380ab6284024a0a.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libcfg_if-08a6c5c01355b760.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libbyteorder-1cd7026b46673e4f.rlib" "D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\libbitflags-1da85fdfe5176d86.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-a21b889540613dfc.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-83bfb8861ef57f40.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-14549e8b52e9aa92.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-917aa5a73e1d450f.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libbacktrace-8b6151daa356874f.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-3a2163f7734147c1.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-617422d63bed4eff.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-0c111a1d0f47d4d2.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-d497a9b0207a701b.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-f48e1371179fb3a7.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-03e655876d14719e.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-586bbf58a5e8a4d5.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-0762d9d8dc651503.rlib" "libpq.lib" "advapi32.lib" "cfgmgr32.lib" "credui.lib" "fwpuclnt.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "ntdll.lib" "opengl32.lib" "secur32.lib" "user32.lib" "winspool.lib" "ws2_32.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib" "/DLL" "/IMPLIB:D:\\a\\actix-web-rest-api-with-jwt\\actix-web-rest-api-with-jwt\\target\\release\\deps\\migrations_macros-3983ee867deb12f4.dll.lib"
  = note: LINK : fatal error LNK1181: cannot open input file 'libpq.lib'

Còn đây là file yml của actions

Mình đã thử nhiều cách như add directory chứa libpq.lib Path và PG_LIB_PATH bằng cmd và powershell. Dùng cách add path trong docs của GitHub và cài đặt postgreSQL nhưng vẫn không được

Mình đang nghi ngờ 2 vấn đề. Một là environment variable do user add vào không hoạt động với link.exe. Hai là step compile không update env từ step trước đó. Tuy nhiên khoảng thời gian này mình lại quá bận với công việc nên chưa kịp tìm hiểu nguyên do. Đăng lên đây hi vọng ai đó đã có kinh nghiệm về environment variables trên Github Actions giải đáp giúp :smiley:

UPDATE:
Thank you @tntxtnt đã giúp mình fix vụ này :smiling_face_with_three_hearts:


Tóm tắt: set RUSTFLAGS environment variables là đường dẫn tuyệt đối đến directory chứa libpq.lib

- name: Run cargo check
  uses: actions-rs/cargo@v1
  with:
    command: check
    args: --release
  env:
    RUSTFLAGS: -L D:\a\actix-web-rest-api-with-jwt\actix-web-rest-api-with-jwt\libs
4 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?