Merge branch 'feature/cross-mingw' of https://github.com/abeimler/setup-cpp into feature/cross-mingw

This commit is contained in:
abeimler 2023-07-20 12:29:20 +02:00
commit 9af05511cb
29 changed files with 159 additions and 63 deletions

View File

@ -143,6 +143,9 @@ jobs:
- "arch.dockerfile" - "arch.dockerfile"
- "fedora.dockerfile" - "fedora.dockerfile"
- "ubuntu.dockerfile" - "ubuntu.dockerfile"
- "arch-mingw.dockerfile"
- "fedora-mingw.dockerfile"
- "ubuntu-mingw.dockerfile"
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:

View File

@ -36,8 +36,7 @@ RUN pacman -Syuu --noconfirm && \
--cppcheck true \ --cppcheck true \
--gcovr true \ --gcovr true \
--doxygen true \ --doxygen true \
--ccache true \ --ccache true && \
--powershell true && \
# arch cleanup # arch cleanup
pacman -Scc --noconfirm && \ pacman -Scc --noconfirm && \
rm -rf /var/cache/pacman/pkg/* && \ rm -rf /var/cache/pacman/pkg/* && \
@ -46,10 +45,9 @@ RUN pacman -Syuu --noconfirm && \
ENTRYPOINT ["/bin/bash"] ENTRYPOINT ["/bin/bash"]
#### Cross Building (example) #### Cross Building (example)
FROM setup-cpp-arch-mingw AS builder FROM setup-cpp-arch-mingw AS builder-mingw
COPY ./dev/cpp_vcpkg_project /home/app COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \ RUN bash -c 'source ~/.cpprc \
&& task build_cross_mingw' && task build_cross_mingw'

View File

@ -26,8 +26,8 @@ RUN dnf -y install nodejs npm && \
ENTRYPOINT ["/bin/bash"] ENTRYPOINT ["/bin/bash"]
#### Building (example) #### Cross Building (example)
FROM setup-cpp-fedora-mingw AS builder FROM setup-cpp-fedora-mingw AS builder-mingw
COPY ./dev/cpp_vcpkg_project /home/app COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app WORKDIR /home/app

View File

@ -1,7 +1,7 @@
import { readFile, writeFile } from "fs/promises" import { readFile, writeFile } from "fs/promises"
async function main() { async function main() {
const dockerFiles = ["ubuntu", "arch", "fedora"] const dockerFiles = ["ubuntu", "arch", "fedora", "ubuntu-mingw", "arch-mingw", "fedora-mingw"]
await Promise.all( await Promise.all(
dockerFiles.map(async (dockerFile) => { dockerFiles.map(async (dockerFile) => {
const dockerFileContent = await readFile(`./dev/docker/setup-cpp-${dockerFile}.dockerfile`, "utf-8") const dockerFileContent = await readFile(`./dev/docker/setup-cpp-${dockerFile}.dockerfile`, "utf-8")

View File

@ -33,10 +33,9 @@ RUN apt-get update -qq && \
ENTRYPOINT ["/bin/bash"] ENTRYPOINT ["/bin/bash"]
#### Cross Building (example) #### Cross Building (example)
FROM setup-cpp-ubuntu-mingw AS builder FROM setup-cpp-ubuntu-mingw AS builder-mingw
COPY ./dev/cpp_vcpkg_project /home/app COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \ RUN bash -c 'source ~/.cpprc \
&& task build_cross_mingw' && task build_cross_mingw'

View File

@ -0,0 +1,7 @@
#### Cross Building (example)
FROM setup-cpp-arch-mingw AS builder-mingw
COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \
&& task build_cross_mingw'

View File

@ -14,11 +14,3 @@ FROM archlinux:base as runner
COPY --from=builder /home/app/build/my_exe/Release/ /home/app/ COPY --from=builder /home/app/build/my_exe/Release/ /home/app/
WORKDIR /home/app/ WORKDIR /home/app/
ENTRYPOINT ["./my_exe"] ENTRYPOINT ["./my_exe"]
#### Cross Building (example)
FROM setup-cpp-arch-mingw AS builder-mingw
COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \
&& task build_cross_mingw'

View File

@ -0,0 +1,7 @@
#### Cross Building (example)
FROM setup-cpp-fedora-mingw AS builder-mingw
COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \
&& task build_cross_mingw'

View File

@ -14,11 +14,3 @@ FROM fedora:38 as runner
COPY --from=builder /home/app/build/my_exe/Release/ /home/app/ COPY --from=builder /home/app/build/my_exe/Release/ /home/app/
WORKDIR /home/app/ WORKDIR /home/app/
ENTRYPOINT ["./my_exe"] ENTRYPOINT ["./my_exe"]
#### Cross Building (example)
FROM setup-cpp-fedora-mingw AS builder-mingw
COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \
&& task build_cross_mingw'

View File

@ -0,0 +1,28 @@
## base image
FROM archlinux:base as setup-cpp-arch-mingw
RUN pacman -Syuu --noconfirm && \
pacman-db-upgrade && \
# install nodejs
pacman -S --noconfirm --needed nodejs npm && \
# install setup-cpp
npm install -g setup-cpp@v0.32.1 && \
# install the compiler and tools
setup-cpp \
--compiler mingw \
--cmake true \
--ninja true \
--task true \
--vcpkg true \
--python true \
--make true \
--cppcheck true \
--gcovr true \
--doxygen true \
--ccache true && \
# arch cleanup
pacman -Scc --noconfirm && \
rm -rf /var/cache/pacman/pkg/* && \
rm -rf /tmp/*
ENTRYPOINT ["/bin/bash"]

View File

@ -0,0 +1,26 @@
## base image
FROM fedora:38 as setup-cpp-fedora-mingw
# install nodejs
RUN dnf -y install nodejs npm && \
# install setup-cpp
npm install -g setup-cpp@v0.32.1 && \
# install the compiler and tools
setup-cpp \
--compiler mingw \
--cmake true \
--ninja true \
--task true \
--vcpkg true \
--python true \
--make true \
--cppcheck true \
--gcovr true \
--doxygen true \
--ccache true \
--powershell true && \
# cleanup
dnf clean all && \
rm -rf /tmp/*
ENTRYPOINT ["/bin/bash"]

View File

@ -0,0 +1,32 @@
#### Base Image
FROM ubuntu:22.04 as setup-cpp-ubuntu-mingw
RUN apt-get update -qq && \
# install nodejs
apt-get install -y --no-install-recommends nodejs npm && \
# install setup-cpp
npm install -g setup-cpp@v0.32.1 && \
# install the compiler and tools
setup-cpp \
--nala true \
--compiler mingw \
--cmake true \
--ninja true \
--task true \
--vcpkg true \
--python true \
--make true \
--cppcheck true \
--gcovr true \
--doxygen true \
--ccache true \
--powershell true && \
# cleanup
nala autoremove -y && \
nala autopurge -y && \
apt-get clean && \
nala clean --lists && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /tmp/*
ENTRYPOINT ["/bin/bash"]

View File

@ -0,0 +1,7 @@
#### Cross Building (example)
FROM setup-cpp-ubuntu-mingw AS builder-mingw
COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \
&& task build_cross_mingw'

View File

@ -14,11 +14,3 @@ FROM ubuntu:22.04 as runner
COPY --from=builder /home/app/build/my_exe/Release/ /home/app/ COPY --from=builder /home/app/build/my_exe/Release/ /home/app/
WORKDIR /home/app/ WORKDIR /home/app/
ENTRYPOINT ["./my_exe"] ENTRYPOINT ["./my_exe"]
#### Cross Building (example)
FROM setup-cpp-ubuntu-mingw AS builder-mingw
COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \
&& task build_cross_mingw'

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -55,19 +55,19 @@
"test.lint.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/", "test.lint.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/",
"test.lint.prettier": "prettier . --check", "test.lint.prettier": "prettier . --check",
"test.unit": "jest --runInBand", "test.unit": "jest --runInBand",
"build.docker_tests": "pnpm build && node ./dev/scripts/generate-docker-tests.mjs", "build.docker_tests": "pnpm build && node ./dev/docker/__tests__/generate-docker-tests.mjs",
"build.docker.arch": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/arch.dockerfile -t setup-cpp:arch .", "build.docker.arch": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/arch.dockerfile -t setup-cpp:arch .",
"build.docker.fedora": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/fedora.dockerfile -t setup-cpp:fedora .", "build.docker.fedora": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/fedora.dockerfile -t setup-cpp:fedora .",
"build.docker.ubuntu": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/ubuntu.dockerfile -t setup-cpp:ubuntu .", "build.docker.ubuntu": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/ubuntu.dockerfile -t setup-cpp:ubuntu .",
"build.docker.arch.mingw": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/arch.mingw.dockerfile -t setup-cpp:arch-mingw .", "build.docker.arch.mingw": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/arch-mingw.dockerfile -t setup-cpp:arch-mingw .",
"build.docker.fedora.mingw": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/fedora.mingw.dockerfile -t setup-cpp:fedora-mingw .", "build.docker.fedora.mingw": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/fedora-mingw.dockerfile -t setup-cpp:fedora-mingw .",
"build.docker.ubuntu.mingw": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/ubuntu.mingw.dockerfile -t setup-cpp:ubuntu-mingw .", "build.docker.ubuntu.mingw": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/ubuntu-mingw.dockerfile -t setup-cpp:ubuntu-mingw .",
"test.docker.arch": "pnpm build.docker.arch && container-structure-test test --image setup-cpp:arch --config ./dev/docker/__tests__/arch.yml", "test.docker.arch": "pnpm build.docker.arch && container-structure-test test --image setup-cpp:arch --config ./dev/docker/__tests__/arch.yml",
"test.docker.fedora": "pnpm build.docker.fedora && container-structure-test test --image setup-cpp:fedora --config ./dev/docker/__tests__/fedora.yml", "test.docker.fedora": "pnpm build.docker.fedora && container-structure-test test --image setup-cpp:fedora --config ./dev/docker/__tests__/fedora.yml",
"test.docker.ubuntu": "pnpm build.docker.ubuntu && container-structure-test test --image setup-cpp:ubuntu --config ./dev/docker/__tests__/ubuntu.yml", "test.docker.ubuntu": "pnpm build.docker.ubuntu && container-structure-test test --image setup-cpp:ubuntu --config ./dev/docker/__tests__/ubuntu.yml",
"test.docker.arch.mingw": "pnpm build.docker.arch.mingw && container-structure-test test --image setup-cpp:arch-mingw --config ./dev/docker/__tests__/arch.mingw.yml", "test.docker.arch.mingw": "pnpm build.docker.arch.mingw && container-structure-test test --image setup-cpp:arch-mingw --config ./dev/docker/__tests__/arch-mingw.yml",
"test.docker.fedora.mingw": "pnpm build.docker.fedora.mingw && container-structure-test test --image setup-cpp:fedora-mingw --config ./dev/docker/__tests__/fedora.mingw.yml", "test.docker.fedora.mingw": "pnpm build.docker.fedora.mingw && container-structure-test test --image setup-cpp:fedora-mingw --config ./dev/docker/__tests__/fedora-mingw.yml",
"test.docker.ubuntu.mingw": "pnpm build.docker.ubuntu.mingw && container-structure-test test --image setup-cpp:ubuntu-mingw --config ./dev/docker/__tests__/ubuntu.mingw.yml" "test.docker.ubuntu.mingw": "pnpm build.docker.ubuntu.mingw && container-structure-test test --image setup-cpp:ubuntu-mingw --config ./dev/docker/__tests__/ubuntu-mingw.yml"
}, },
"prettier": "prettier-config-atomic", "prettier": "prettier-config-atomic",
"devDependencies": { "devDependencies": {

View File

@ -60,8 +60,12 @@ export async function installCompiler(
case "mingw": case "mingw":
case "cygwin": case "cygwin":
case "msys": { case "msys": {
const gccVersion = (compiler === "mingw")? getVersion("mingw", version, osVersion) : getVersion("gcc", version, osVersion) const gccVersion =
const installationInfo = (compiler === "mingw")? await setupMingw(gccVersion, join(setupCppDir, "gcc"), arch) : await setupGcc(gccVersion, join(setupCppDir, "gcc"), arch) compiler === "mingw" ? getVersion("mingw", version, osVersion) : getVersion("gcc", version, osVersion)
const installationInfo =
compiler === "mingw"
? await setupMingw(gccVersion, join(setupCppDir, "gcc"), arch)
: await setupGcc(gccVersion, join(setupCppDir, "gcc"), arch)
if (hasLLVM) { if (hasLLVM) {
// remove back the added CPPFLAGS of LLVM that include the LLVM headers // remove back the added CPPFLAGS of LLVM that include the LLVM headers

View File

@ -153,9 +153,7 @@ export async function setupMingw(version: string, setupDir: string, arch: string
if (isArch()) { if (isArch()) {
installationInfo = await setupPacmanPack("mingw-w64-gcc", version) installationInfo = await setupPacmanPack("mingw-w64-gcc", version)
} else if (hasDnf()) { } else if (hasDnf()) {
installationInfo = await setupDnfPack([ installationInfo = await setupDnfPack([{ name: "mingw64-gcc", version }])
{ name: "mingw64-gcc", version },
])
} else if (isUbuntu()) { } else if (isUbuntu()) {
installationInfo = await setupAptPack([ installationInfo = await setupAptPack([
{ name: "mingw-w64", version, repositories: ["ppa:ubuntu-toolchain-r/test"] }, { name: "mingw-w64", version, repositories: ["ppa:ubuntu-toolchain-r/test"] },

View File

@ -2,6 +2,7 @@ import { InstallationInfo } from "./setupBin"
import { execRootSync } from "admina" import { execRootSync } from "admina"
import { info, warning } from "ci-log" import { info, warning } from "ci-log"
import { execa, execaSync } from "execa" import { execa, execaSync } from "execa"
import which from "which"
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
let didUpdate: boolean = false let didUpdate: boolean = false
@ -13,6 +14,11 @@ export async function setupPacmanPack(name: string, version?: string, aur?: stri
const pacman = "pacman" const pacman = "pacman"
if (aur === "yay" && which.sync("yay", { nothrow: true }) === null) {
// TODO: install yay automatically
throw new Error(`yay is needed for ${name}, but it is not installed, please install it manually first`)
}
// yay can't run as root, so skip update // yay can't run as root, so skip update
if (!didUpdate && aur !== "yay") { if (!didUpdate && aur !== "yay") {
execRootSync(pacman, ["-Sy", "--noconfirm"]) execRootSync(pacman, ["-Sy", "--noconfirm"])

View File

@ -28,5 +28,10 @@
"outDir": "./dist" "outDir": "./dist"
}, },
"compileOnSave": false, "compileOnSave": false,
"include": ["./src", "dev/scripts", "packages/untildify-user/untildify.ts"] "include": [
"./src",
"dev/scripts",
"packages/untildify-user/untildify.ts",
"dev/docker/__tests__/generate-docker-tests.mjs"
]
} }