Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/c_tools.nit
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,18 @@ class ExternFile
# Filename relative to the nit-compile folder
var filename: String

# Identifier of the compilation context, used to prevent collisions
# between the builds of two parallel jobs
var build_context_id: String is writable, noinit

# The name of the target in the Makefile
# Usually the produced .o file
fun makefile_rule_name: String is abstract

# The content of the rule in the make
# Usually the one-line shell command after the tabulation
fun makefile_rule_content: String is abstract
# The lines of the rule in the make
#
# The shell commands after the tabulation.
fun makefile_rule_content: Array[String] is abstract

fun compiles_to_o_file: Bool do return false

Expand Down Expand Up @@ -150,7 +155,7 @@ class ExternCFile
if not pkgconfigs.is_empty then
pkg = "`pkg-config --cflags {pkgconfigs.join(" ")}`"
end
return "$(CC) $(CFLAGS) -Wall -Wno-unused-function {self.cflags} {pkg} -c -o {o} {ff}"
return ["$(CC) $(CFLAGS) -Wall -Wno-unused-function {self.cflags} {pkg} -c -o {o} {ff}"]
end

redef fun compiles_to_o_file do return true
Expand Down
11 changes: 9 additions & 2 deletions src/compiler/abstract_compiler.nit
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class MakefileToolchain
var gc_chooser = new ExternCFile("gc_chooser.c", cc_opt_with_libgc)
if cc_opt_with_libgc != "" then gc_chooser.pkgconfigs.add "bdw-gc"
compiler.extern_bodies.add(gc_chooser)
var clib = toolcontext.nit_dir / "clib"
var clib = toolcontext.nit_dir.as(not null) / "clib"
compiler.files_to_copy.add "{clib}/gc_chooser.c"
compiler.files_to_copy.add "{clib}/gc_chooser.h"

Expand All @@ -255,6 +255,12 @@ class MakefileToolchain
compiler.finalize_ffi_for_module(m)
end

# Prevent collision in the build files of two different parallel jobs
# by assigning them a somewhat unique identifier
for f in compiler.extern_bodies do
f.build_context_id = compiler.realmainmodule.c_name
end

# Copy original .[ch] files to compile_dir
for src in compiler.files_to_copy do
var basename = src.basename
Expand Down Expand Up @@ -537,7 +543,8 @@ endif
for f in compiler.extern_bodies do
var o = f.makefile_rule_name
makefile.write("{o}: {f.filename}\n")
makefile.write("\t{f.makefile_rule_content}\n\n")
for line in f.makefile_rule_content do makefile.write("\t{line}\n")
makefile.write("\n")
dep_rules.add(f.makefile_rule_name)

if f.compiles_to_o_file then ofiles.add(o)
Expand Down
2 changes: 1 addition & 1 deletion src/ffi/cpp.nit
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class ExternCppFile
var mmodule: MModule

redef fun makefile_rule_name do return "{filename}.o"
redef fun makefile_rule_content do return "$(CXX) $(CFLAGS) {mmodule.cppflags[""].join(" ")} -c {filename} -o {filename}.o"
redef fun makefile_rule_content do return ["$(CXX) $(CFLAGS) {mmodule.cppflags[""].join(" ")} -c {filename} -o {filename}.o"]
redef fun compiles_to_o_file do return true
end

Expand Down
10 changes: 9 additions & 1 deletion src/ffi/java.nit
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,15 @@ class JavaFile
fun full_name: String do return filename.basename(".java")

redef fun makefile_rule_name do return full_name.replace(".", "/") + ".class"
redef fun makefile_rule_content do return "javac {filename} -d ."

# Compile to a directory limited to this build then atomically move the
# result into place, so concurrent builds of the same class (eg. shared
# support classes like `nit.app.NitObject`) never load a partial file.
redef fun makefile_rule_content do return [
"mkdir -p ffi_java_{build_context_id}",
"javac -implicit:none {filename} -d ffi_java_{build_context_id}",
"mv -f ffi_java_{build_context_id}/{makefile_rule_name} {makefile_rule_name}"]

redef fun add_to_jar do return true
end

Expand Down
2 changes: 1 addition & 1 deletion src/ffi/objc.nit
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class ExternObjCFile

redef fun makefile_rule_name do return "{filename.basename(".m")}_m.o"
redef fun makefile_rule_content do
return "clang $(CFLAGS) -c {filename} -o {makefile_rule_name}"
return ["clang $(CFLAGS) -c {filename} -o {makefile_rule_name}"]
end
redef fun compiles_to_o_file do return true
end
Expand Down
Loading