Skip to content

Commit

Permalink
precompile bits/stdc++.h
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodingwizard committed Jul 8, 2024
1 parent 9416852 commit bb1eeee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
FROM public.ecr.aws/lambda/python:3.12

RUN dnf install -y gcc-c++

# For -fsanitize=undefined and -fsanitize=address
RUN dnf install -y libasan libubsan

# Precompile bits/stdc++.h: https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html
# I believe flags like -Wall are ignored, but flags like -std, -O2, and -fsanitize=address must
# match the flags used to precompile the header.
RUN mkdir -p /precompiled-headers/bits/stdc++.h.gch
RUN g++ -std=c++11 -O2 -o /precompiled-headers/bits/stdc++.h.gch/01 /usr/include/c++/11/x86_64-amazon-linux/bits/stdc++.h
RUN g++ -std=c++17 -O2 -o /precompiled-headers/bits/stdc++.h.gch/02 /usr/include/c++/11/x86_64-amazon-linux/bits/stdc++.h
RUN g++ -std=c++23 -O2 -o /precompiled-headers/bits/stdc++.h.gch/03 /usr/include/c++/11/x86_64-amazon-linux/bits/stdc++.h
RUN g++ -std=c++11 -O2 -fsanitize=address -o /precompiled-headers/bits/stdc++.h.gch/04 /usr/include/c++/11/x86_64-amazon-linux/bits/stdc++.h
RUN g++ -std=c++17 -O2 -fsanitize=address -o /precompiled-headers/bits/stdc++.h.gch/05 /usr/include/c++/11/x86_64-amazon-linux/bits/stdc++.h
RUN g++ -std=c++23 -O2 -fsanitize=address -o /precompiled-headers/bits/stdc++.h.gch/06 /usr/include/c++/11/x86_64-amazon-linux/bits/stdc++.h

RUN dnf install -y java-21-amazon-corretto-devel
RUN dnf install -y time

Expand Down
2 changes: 1 addition & 1 deletion src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn compile(compile_request: CompileRequest) -> Result<CompileResponse> {
.map_err(|_| anyhow!("failed to convert output_file_path into string"))?;

let command = format!(
"g++ -o {} {} program.cpp",
"g++ -I/precompiled-headers -o {} {} program.cpp",
output_file_path, compile_request.compiler_options
);
let compile_output = run_command(
Expand Down

0 comments on commit bb1eeee

Please sign in to comment.