Skip to content

Commit

Permalink
cmake: emscripten experimental support
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Sep 7, 2023
1 parent d3afb02 commit 0fdba33
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/amd64_web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ref: https://github.com/docker-library/official-images
name: amd64 Web

on: [push, pull_request, workflow_dispatch]

jobs:
Distros:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check docker
run: |
docker info
docker buildx ls
- name: Build env image
run: make --directory=cmake web_env
- name: Build devel project
run: make --directory=cmake web_devel
- name: Build project
run: make --directory=cmake web_build
- name: Test project
run: make --directory=cmake web_test
42 changes: 41 additions & 1 deletion cmake/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,46 @@ $(foreach stage,$(TOOLCHAIN_STAGES),$(eval $(call toolchain-stage-target,$(stage
clean_toolchains: $(addprefix clean_toolchain_, $(TOOLCHAIN_STAGES))
-rmdir $(addprefix cache/, $(TOOLCHAIN_TARGETS))

#########
## WEB ##
#########
WEB_STAGES := env devel build test

define make-web-stage-target =
#$$(info STAGE: $1)
#$$(info Create target: web_$1.)
.PHONY: web_$1
web_$1: docker/web/Dockerfile
#@docker image rm -f ${IMAGE}:web_$1 2>/dev/null
${DOCKER_BUILD_CMD} --target=$1 --tag ${IMAGE}:web_$1 -f $$< ..

#$$(info Create target: save_web_$1 (debug).)
.PHONY: save_web_$1
save_web_$1: cache/web/docker_$1.tar
cache/web/docker_$1.tar: web_$1
@rm -f $$@
mkdir -p cache/web
docker save ${IMAGE}:web_$1 -o $$@

#$$(info Create target: sh_web_$1 (debug).)
.PHONY: sh_web_$1
sh_web_$1: web_$1
${DOCKER_RUN_CMD} -it --name ${IMAGE}_web_$1 ${IMAGE}:web_$1

#$$(info Create target: clean_web_$1.)
.PHONY: clean_web_$1
clean_web_$1:
docker image rm -f ${IMAGE}:web_$1 2>/dev/null
rm -f cache/web/docker_$1.tar
endef

$(foreach stage,$(WEB_STAGES),$(eval $(call make-web-stage-target,$(stage))))

## MERGE ##
.PHONY: clean_web
clean_web: $(addprefix clean_web_, $(WEB_STAGES))
rm -f cache/web

#############
## VAGRANT ##
#############
Expand Down Expand Up @@ -451,7 +491,7 @@ $(clean_glop_targets): clean_glop_%
###########
## CLEAN ##
###########
targets = $(addprefix clean_, $(DISTROS))
targets = $(addprefix clean_, $(DISTROS)) clean_web
vms = $(addprefix clean_, $(VMS))
glops = $(addprefix clean_glop_, $(STAGES))
.PHONY: clean $(targets)
Expand Down
24 changes: 24 additions & 0 deletions cmake/docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Create a virtual environment with all tools installed
# ref: https://hub.docker.com/_/archlinux/
FROM archlinux:latest AS env
# Install system build dependencies
ENV PATH=/usr/local/bin:$PATH
RUN pacman -Syu --noconfirm git base-devel cmake
RUN cmake -version
RUN pacman -Syu --noconfirm nodejs emscripten
ENV PATH=/usr/lib/emscripten:$PATH
RUN emcc -v

# Add the library src to our build env
FROM env AS devel
WORKDIR /home/project
COPY . .

FROM devel AS build
RUN emcmake cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release -DBUILD_DEPS=ON
RUN cmake --build build --target all -v
#RUN cmake --build build --target install -v

FROM build AS test
#RUN CTEST_OUTPUT_ON_FAILURE=1 cmake --build build --target test
RUN cd build && ctest -V
2 changes: 1 addition & 1 deletion ortools/base/sysinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int64_t GetProcessMemoryUsage() {
int64_t resident_memory = t_info.resident_size;
return resident_memory;
}
#elif defined(__GNUC__) && !defined(__FreeBSD__) // LINUX
#elif defined(__GNUC__) && !defined(__FreeBSD__) && !defined(__EMSCRIPTEN__) // LINUX
int64_t GetProcessMemoryUsage() {
unsigned size = 0;
char buf[30];
Expand Down

0 comments on commit 0fdba33

Please sign in to comment.