Skip to content

Commit

Permalink
Merge pull request #47801 from fastly/jkarneges/makefiles-in-target
Browse files Browse the repository at this point in the history
generate individual c++ makefiles in target dir
  • Loading branch information
jkarneges authored Nov 27, 2023
2 parents 5c0a42b + 56d508a commit 8637d37
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 42 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ vendor
/conf.log
/conf.pri
/Makefile
/src/cpp/Makefile
/src/cpp/cpp/Makefile
/src/cpp/tests/Makefile
/src/runner/certs/*.crt
/src/runner/certs/*.key
/postbuild/conf.pri
/postbuild/Makefile
/postbuild/*.inst
/config
Expand Down
49 changes: 35 additions & 14 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::env;
use std::error::Error;
use std::ffi::OsStr;
use std::fs;
use std::io::{self, BufRead, BufReader, Write};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -218,45 +219,64 @@ fn main() -> Result<(), Box<dyn Error>> {
let run_dir = env_or_default("RUNDIR", &default_vars);

let root_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
let cpp_src_dir = root_dir.join(Path::new("src/cpp"));
let cpp_lib_dir = root_dir.join(Path::new("target/cpp"));
let cpp_src_dir = root_dir.join("src/cpp");
let cpp_tests_src_dir = root_dir.join("src/cpp/tests");
let cpp_out_dir = root_dir.join("target/cpp");

for dir in ["moc", "obj", "test-moc", "test-obj", "test-work"] {
fs::create_dir_all(cpp_lib_dir.join(Path::new(dir)))?;
fs::create_dir_all(cpp_out_dir.join(dir))?;
}

write_cpp_conf_pri(&cpp_lib_dir.join(Path::new("conf.pri")))?;
write_cpp_conf_pri(&cpp_out_dir.join("conf.pri"))?;

write_postbuild_conf_pri(
&Path::new("target").join(Path::new("postbuild_conf.pri")),
&Path::new("postbuild").join("conf.pri"),
&bin_dir,
&lib_dir,
&config_dir,
&run_dir,
&log_dir,
)?;

if !cpp_src_dir.join("Makefile").try_exists()? {
assert!(Command::new(&qmake_path)
.args(["-o", "Makefile", "cpp.pro"])
.current_dir(&cpp_src_dir)
.status()?
.success());
}
assert!(Command::new(&qmake_path)
.args([
OsStr::new("-o"),
cpp_out_dir.join("Makefile").as_os_str(),
cpp_src_dir.join("cpp.pro").as_os_str(),
])
.status()?
.success());

assert!(Command::new(&qmake_path)
.args([
OsStr::new("-o"),
cpp_out_dir.join("Makefile.test").as_os_str(),
cpp_tests_src_dir.join("tests.pro").as_os_str(),
])
.status()?
.success());

let proc_count = thread::available_parallelism().map_or(1, |x| x.get());

assert!(Command::new("make")
.args(["-f", "Makefile"])
.args(["-j", &proc_count.to_string()])
.current_dir(&cpp_out_dir)
.status()?
.success());

assert!(Command::new("make")
.args(["-f", "Makefile.test"])
.args(["-j", &proc_count.to_string()])
.current_dir(&cpp_src_dir)
.current_dir(&cpp_out_dir)
.status()?
.success());

println!("cargo:rustc-env=APP_VERSION={}", get_version());
println!("cargo:rustc-env=CONFIG_DIR={}/pushpin", config_dir);
println!("cargo:rustc-env=LIB_DIR={}/pushpin", lib_dir);

println!("cargo:rustc-link-search={}", cpp_lib_dir.display());
println!("cargo:rustc-link-search={}", cpp_out_dir.display());

#[cfg(target_os = "macos")]
println!(
Expand All @@ -267,6 +287,7 @@ fn main() -> Result<(), Box<dyn Error>> {
#[cfg(not(target_os = "macos"))]
println!("cargo:rustc-link-search={}", qt_install_libs.display());

println!("cargo:rerun-if-env-changed=RELEASE");
println!("cargo:rerun-if-env-changed=PREFIX");
println!("cargo:rerun-if-env-changed=BINDIR");
println!("cargo:rerun-if-env-changed=CONFIGDIR");
Expand Down
2 changes: 1 addition & 1 deletion postbuild/postbuild.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = aux

include($$OUT_PWD/../target/postbuild_conf.pri)
include(conf.pri)

root_dir = $$PWD/..
bin_dir = $$root_dir/bin
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ distclean: clean

check:
cd .. && cargo test $(cargo_flags)

install:
2 changes: 1 addition & 1 deletion src/cpp/cpp/cpp.pri → src/cpp/cpp.pri
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QMAKE_CXXFLAGS += $$(CXXFLAGS)
QMAKE_CFLAGS += $$(CFLAGS)
QMAKE_LFLAGS += $$(LDFLAGS)

SRC_DIR = $$PWD/..
SRC_DIR = $$PWD
QZMQ_DIR = $$SRC_DIR/qzmq
RUST_DIR = $$SRC_DIR/../rust

Expand Down
18 changes: 12 additions & 6 deletions src/cpp/cpp.pro
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
TEMPLATE = subdirs
TEMPLATE = lib
CONFIG -= app_bundle
CONFIG += staticlib c++11
QT -= gui
QT += network
TARGET = pushpin-cpp
DESTDIR = ../../target/cpp

cpp.subdir = cpp
cpp_build_dir = $$OUT_PWD

tests.subdir = tests
MOC_DIR = $$cpp_build_dir/moc
OBJECTS_DIR = $$cpp_build_dir/obj

SUBDIRS += \
cpp \
tests
include($$cpp_build_dir/conf.pri)
include(cpp.pri)
15 changes: 0 additions & 15 deletions src/cpp/cpp/cpp.pro

This file was deleted.

4 changes: 2 additions & 2 deletions src/cpp/tests/tests.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ QT *= network testlib
TARGET = pushpin-cpptest
DESTDIR = ../../../target/cpp

cpp_build_dir = $$OUT_PWD/../../../target/cpp
cpp_build_dir = $$OUT_PWD

MOC_DIR = $$cpp_build_dir/test-moc
OBJECTS_DIR = $$cpp_build_dir/test-obj
Expand All @@ -15,7 +15,7 @@ SRC_DIR = $$PWD/..
QZMQ_DIR = $$SRC_DIR/qzmq
RUST_DIR = $$SRC_DIR/../rust

include($$PWD/../../../target/cpp/conf.pri)
include($$cpp_build_dir/conf.pri)

INCLUDEPATH += $$SRC_DIR
INCLUDEPATH += $$SRC_DIR/proxy
Expand Down

0 comments on commit 8637d37

Please sign in to comment.